You can have as many terminals and shells open at once as you want. Just use M-x rename-buffer
to change the name of an existing *term*
or *shell*
buffer, and the next time you do M-x term
or M-x shell
, a brand new buffer will be created. In the case of M-x shell
, a prefix argument will cause you to be prompted for the name of the new shell buffer, as offby1 noted.
A few years ago I had a job where I had to regularly log in to various production servers named "host01.foo.com", "host02.foo.com", etc. I wrote a little function like this one to make it easier to manage them all:
(defun ssh-to-host (num)
(interactive "P")
(let* ((buffer-name (format "*host%02d*" num))
(buffer (get-buffer buffer-name)))
(if buffer
(switch-to-buffer buffer)
(term "/bin/bash")
(term-send-string
(get-buffer-process (rename-buffer buffer-name))
(format "ssh host%02.foo.com\r" num)))))
Then I bound this command to (say) s-h (super H), enabling me to just type M-5 s-h. If I didn't already have a buffer named *host05*
, it would start a new terminal emulator buffer, rename it to *host05*
, and ssh me into host05.foo.com. If buffer *host05*
already existed, it would simply switch me to it. Quite handy!