I am doing Rails development and find that I need to spawn a shell, rename the buffer (e.g. webrick), then kick off the command (rails s) and then do the whole thing over again if I want a rails console or rails dbconsole, rspec, spork, etc. every time I start up emacs.
I am hoping for something like this:
(defun spawn-shell ()
"Invoke shell test"
(with-temp-buffer
(shell (current-buffer))
(process-send-string nil "echo 'test1'")
(process-send-string nil "echo 'test2'")))
I don't want the shell to go away when it exits because the output in the shell buffer is important and some times I need to kill it and restart it but I don't want to lose that history.
Essentially, I want to take the manual process and make it invokable.
Any help is much appreciated
Tom
Perhaps this version of spawn-shell
will do what you want:
(defun spawn-shell (name)
"Invoke shell test"
(interactive "MName of shell buffer to create: ")
(pop-to-buffer (get-buffer-create (generate-new-buffer-name name)))
(shell (current-buffer))
(process-send-string nil "echo 'test1'\n")
(process-send-string nil "echo 'test2'\n"))
It prompts for a name to use when you run it interactively (M-x spawn-shell). It creates a new buffer based on the input name using generate-new-buffer-name
, and you were missing the newlines on the end of the strings you were sending to the process.
If your only problem is that the shell buffer disappears after the commands have been executed, why not use get-buffer-create
instead of with-temp-buffer
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With