0

I want to add a command to dired-mode, which executes a shell command on the highlighted file. For example, from Bash, I can run qvm-copy {FILENAME}. I would like to replicate this behavior, but from within a dired buffer, executing on the highlighted file. How can I accomplish this?

7
  • 1
    dired-do-shell-command, usually bound to !? Commented Apr 23 at 16:53
  • This seems close. I'm trying to bind this to the "C" key within a hydra. So, for example, would that be ("C" dired-do-shell-command qvm-copy)? Or do I need some different elisp?
    – ch-pub
    Commented Apr 23 at 17:11
  • Sorry: I don't know the hydra syntax but whatever it is, you want to execute (dired-do-shell-command "qvm-copy"). Commented Apr 23 at 17:32
  • This does not quite seem to work for me. Even without hydra, if I just create a function, (defun qcopy () (interactive) (dired-do-shell-command "qvm-copy")), this runs, but returns the output: "Shell command succeeded with no output". This is not anticipated. Whereas, if I execute ! from dired, then type "qvm-copy" then ENTER, it opens a pop-up, as I expected. I am trying to replicate this behavior, but with a keybind (so I don't have to keep typing "qvm-copy" ENTER).
    – ch-pub
    Commented Apr 23 at 18:16
  • 2
    Try (dired-do-shell-command "qvm-copy ?") and see the doc string of dired-do-shell-command for more details.
    – NickD
    Commented Apr 23 at 18:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.