I'm something of an Emacs newbie. I would like to run a shell script I've written and insert the output into the buffer I'm working in. But the script requires some interaction, so ideally I'd like a workflow where I:
- Call a command from the main buffer
- Shell or Term mode opens, I interact with the script, the script gives final output and exits
- Final output is inserted at the point in my main buffer
Is this feasible?
I've read some of the documentation on shell mode, the GNU documentation on running shell commands in Emacs and other material I've been able to find, but I can't find anything that addresses this issue specifically. I may have just missed it, of course.
shell-command-to-stringcan be used to return a value and that can be modified as needed; e.g., by modifying the string. E.g.,(insert (car (split-string (shell-command-to-string "date") "\n"))). To enter commands underneath the shell hood, there are the functionscomint-send-stringandcomint-send-input, the latter of which is required if the former does not contain a\nat the end of the string.shell-modemight be useful to some as well.pwsh -noLogo -NoProfile -Command "Read-Host -Prompt 'prompt'"in a Windows Terminal running Powershell, I get prompted for input. However if I run this same command usingshell-commandfrom inside emacs (M-!), I am informed in the minibuffer that the command completed successfully, but I am never prompted for any input.