Skip to content

Instantly share code, notes, and snippets.

@kidd
Created April 21, 2021 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidd/d7dff019010e5b0eb5ae0aa9ce6c7580 to your computer and use it in GitHub Desktop.
Save kidd/d7dff019010e5b0eb5ae0aa9ce6c7580 to your computer and use it in GitHub Desktop.
(defun shell-execute ()
(interactive)
(let ((file-buffer (buffer-file-name))
(command (read-shell-command "Shell command: " nil nil
(let ((filename
(cond
(buffer-file-name)
((eq major-mode 'dired-mode)
(dired-get-filename nil t)))))
(and filename (file-relative-name filename))))))
(shell-command (replace-regexp-in-string "%" file-buffer command))))
(global-set-key (kbd "M-!") 'shell-execute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment