1

i have zero coding skills but somehow (mainly goggle) managed to write this script

(defun z/dired-shell-other-window-beets ()
  "Open a shell with dired path in a new window and issue beet import on file at point "
  (interactive)
  (let ((buf (shell)))
    (switch-to-buffer (other-buffer buf))
    (switch-to-buffer-other-window buf)
(insert (concat "beet import "  (dired-copy-filename-as-kill) ))

))

what im trying to do is issue a interactive shell command (beet import) on the current folder point is on in dired

i managed to get the beet import inserted to the new shell buffer thats opened but how do i follow that with the current dir name/path?

3

So there are already two keybindings that do something similar which we'll talk about and then we'll talk about making you're own command. First of all you can use dired-do-async-shell-command which is bound to & in dired. This will prompt for a command and will execute the command on the name of the filename that is marked or under your point. So you press & and then type "beet import" this will run your command! In a similar vein there is also dired-do-shell-command which is bound to !

The last option is if you will be calling this very very often you can write your own function modeled after dired-do-async-shell-command like this:

(defun dired-do-beet-import (&optional arg file-list)
  (interactive
   (let ((files (dired-get-marked-files t current-prefix-arg)))
     (list
      current-prefix-arg
      files)))
  (dired-do-shell-command "beet import" arg file-list))

This version of the command opens a subshell to run the command in, it has less error checking and it only works for the file under the point and not for any files that are marked:

(defun dired-do-beet-import ()
  (interactive)
  (let ((command (concat "beet import " (format "%S" (dired-get-filename)))))
    (with-current-buffer (shell)
      (insert command)
      (comint-send-input))))
  • Thx so much Jules. the function above does work! yet i really need it to run in a shell since sometimes there is interaction needed with the beets command. is there anyway to open a shell window and see what the command is doing in addition to interacting with it (choose options) in the shell window? – zeltak Jun 14 '16 at 15:14
  • I updated my answer with another version – Jules Jun 14 '16 at 15:31
  • thx so much again. this is pretty epic ;-) yet there is still a small issue i think is due to not escaping the paths. when i issue the command i get this error: $ beet import /home/zeltak/mreview/Bangles/1986 Different Light error: no such file or directory: /home/zeltak/mreview/Bangles/1986 when i go and manually escape the path to $ beet import /home/zeltak/mreview/Bangles/1986\ Different\ Light/ the command works! i assume there is a way to escape the path in eshell properly? also small annoyance by me can the eshell open in a new split window as my original script ;-) – zeltak Jun 14 '16 at 15:38
  • Should be fixed! Cheers! – Jules Jun 14 '16 at 15:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.