Why Nostr? What is Njump?
2024-06-22 10:28:39
in reply to

Visuwesh :emacs_sink: on Nostr: It is M-|. RET would make it more similar to shell-mode now that I think about it but ...

It is M-|. RET would make it more similar to shell-mode now that I think about it but I think I would be more surprised when RET does not write a newline.

I actually wrote the command for running commands in my notes and in README files (after verifying) but it became more useful the moment I realised I could just use shell-command+ instead (allowing for sam style replacements, command substitution, etc.). Thankfully since almost everything is text in Emacs, it became handy in M-!'s buffer too.

(defun vz/execute-region-as-shell-command (beg end)
"Execute the region from BEG to END as shell command.
If the region is not active, then the current line is executed
instead. For convenience, \"[%$#] \" is stripped from the
beginning of the string, if present. If the command begins with
#, then it executed as root using the doas TRAMP method.

The command is actually passed to `shell-command+'."
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-end-position))))
(let* ((string (string-trim-left (buffer-substring beg end)))
(doasp (string-prefix-p "#" string))
(string (string-trim-left string "\\`\\(?:[%$#][[:space:]]\\)?")))
(shell-command+ (concat (and doasp "doas ") string) (point) (point))))
Author Public Key
npub1rw7xqzxmshsg45kwh33ah0cln24tr9yc8kt7a6uatelq0qgzlqhqghnfr2