1

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.

  • 1
    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 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 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 at 10:32
  • @Tobias I tried this advice but it doesn't have any effect in my emacs 24. – rph Jul 10 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.