I wanted to run a script in the location of the current buffer, or, if it is a dired buffer - to run the script on the current dired directory. The current dired directory seems to be stored in dired-directory
variable. Indeed it is - but when I try to make use of it - it sometimes gives me the previous dirs instead of the current one:
(defun bk-konsoles ()
"Calls: bk-konsoles.bash"
(interactive)
(let ((curDir (if (memq major-mode '(dired-mode sr-mode)) dired-directory
(if (buffer-file-name) (file-name-directory (buffer-file-name))))))
(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") curDir " & disown") nil nil)
(kill-buffer "*Shell Command Output*")
(delete-other-windows)))
How do I make the defun get the right value of the dired's current directory?
You can use the variable default-directory
.
In this case you don't need to check if you're in the dired mode or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With