Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Improved "open with" suggestions for dired mode in Emacs

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.org
Octocat-spinner-32 runner.el
README.org

This library links a set of shell commands to file or directory names. These commands can then be used in dired mode using dired-do-shell-command (by pressing “!”). Since this library modifies the behavior of dired-guess-shell-alist-user, the command syntax will follow that variable’s syntax (see the documentation of dired-guess-shell-alist-user for more).

Features

  • Provides a widget.el interface to add, edit, and sort shell commands.
  • Gets rid of the “A command is running - kill it? Yes or No?” message.
  • If command string contains `{run:out}’, then keep output in a specially named buffer.
  • If command string contains “{run:shell}”, then run command using the function specified in runner-shell-function.
  • If runner-run-in-background is set to t, send the stdout buffer to the background except when the command string includes “{run:out}”.
  • If runner-show-label is set to t, display label next to each command.

Install

Put this file in your Emacs-Lisp load path, and add the following into your $HOME/.emacs startup file.

(require 'runner)

The functions dired-guess-default (from dired-x.el) and dired-run-shell-command (from dired-aux.el) will be redefined.

Usage

While in dired mode, position point on any file or directory you wish to add a shell command to, then do:

M-x runner-add-file (for file or directory names)
M-x runner-add-extension (for file extension)

A new buffer will be created allowing you to specify what commands to run.

A file name or extension can be linked to multiple set of commands. You can view and edit which pattern is being applied to a file by positioning point on a file and running,

M-x runner-edit-file-at-point

You can also add, edit, or delete any specific pattern by doing:

M-x runner-add-empty
M-x runner-edit
M-x runner-delete

The command database will be saved to the variable runner-init-file (default is “~/.emacs.d/runner-conf.el”). You may choose a different location by doing:

M-x customize-variable runner-init-file

Tips

Oftentimes I have commands that rely on the base name of a file (sans extension) being available. I wrote the following bash script and called it run-f.

#!/bin/bash
#
# Return the base file name sans extension. If more than one file is
# passed, just return the first one.
#
for file in "$@"
do
    FILESANSEXT="${file%.*}"
    echo "$FILESANSEXT"
    exit;
done

Now I can easily pass multiple commands from runner.el. For instance, the following command creates a text file from a scanned PDF using ocrodjvu:

{run:out} pdf2djvu -o "$(run-f ? ).djvu" ? && ocrodjvu -o "$(run-f ? )_ocr.djvu" "$(run-f ? ).djvu" && djvutxt "$(run-f ? )_ocr.djvu" "$(run-f ? ).txt" &
Something went wrong with that request. Please try again.