In dired-mode I can type ! to use the selected file as an argument for a command. For instance, if I type ! rm <RET> it will run the command rm filename.

What I wanted is a short-key to run the file (if it is executable). Let's say I have this short-key mapped to @. Then I would type @ arg <RET> and it would run the selected file with the given argument, i.e., ./filename arg.

  • 2
    Are you aware that dired-smart-shell-command offers you the file below point as default? If you are at an executable file in a dired buffer press M-! and <down>. The file at point is inserted in the minibuffer. That is almost what you want. There are two things that would be better. 1st) If a space would be appended to the file name 2nd) If point would be placed at the end of the default input.
    – Tobias
    Jul 3 '19 at 15:52
  • Thanks, I did not know about this. It is certainly helpful. But inserting the ./ still annoys me a little.
    – rph
    Jul 4 '19 at 9:31
  • The following advice adds the dot in the second default value: (defun my-add-shell-commands-filter-ret (ret) (cons (car ret) (cons (concat "./" (car ret)) (cdr ret)))) (advice-add 'minibuffer-default-add-shell-commands :filter-return #'my-add-shell-commands-filter-ret)
    – Tobias
    Jul 4 '19 at 10:32
  • @Tobias I tried this advice but it doesn't have any effect in my emacs 24.
    – rph
    Jul 10 '19 at 13:58

This site is temporarily in read only mode and not accepting new answers.

Browse other questions tagged .