I can run a shell command quickly by hitting M-!. One thing I’d like to do is perform shell quick operations on the current file. An example would be checking the file out through perforce:
M-! p4 edit buffer-file-name RET
(Yes there are perforce integrations, but I’m more interested in the minishell/variable problem rather than a specific workflow)
Of course, the buffer-file-name variable is not evaluated before the command is sent to the shell.
Is there an easy on-the-fly way to do this? Or will I have to roll a custom elisp function?
Indeed using C-u M-: is almost right. I’m not so sure about using
shell-quote-argumentineval-to-shell-argumentsince it only works on strings making it impossible to useeval-to-shell-argumentto insert a number or a symbol. You could try something like:and then bind this function in your minibuffer with
(define-key minibuffer-local-map [?\M-:] 'sm-minibuffer-insert-val).Of course, if the only thing you ever want to insert is the buffer-file-name, then your
execute-shell-command-on-bufferis simpler.