If I want to execute a shell command on a region I know I can use
M-|, what if the command I want to
redirect my selection does not accept redirection to it's standard input.
In my case I would like to redirect my an active region to
python -m doctest
In the shell I could use process substitution like
python -m doctest -v
<( echo '>>> print("hello")\nhello')
Is there a direct way to that in emacs, or do I need to write some elisp to get the active region and build the shell command myself?
Not sure if this is a good solution and what will happen if the string contains quotes like
', but seems to work at the moment, I'll appreciate any suggestions.
(defun my/python/run-doctest-on-region () (interactive) (let* ((text-to-shell-cmd (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (buffer-substring-no-properties (point-min) (point-max)))) (cmd (concat "python -m doctest -v <( echo '" text-to-shell-cmd "')"))) (shell-command cmd)))