6

I'm interested in naming Emacs buffers. In particular I'd like to give names to shell buffers that I've started. That way I can easily tell them apart when switching buffers.

  • What about using the current directory of the shell? – choroba Apr 26 '17 at 7:54
  • 3
    I would normally call C-u M-x shell - in this way Emacs offers to name the buffer it creates. But if I forget, there's always the M-x rename-buffer. Or are you asking for an advise on what that name should be? – wvxvw Apr 26 '17 at 8:59
  • @wvxvw: Please consider posting that as an answer. – Drew Apr 26 '17 at 14:03
  • 1
    FWIW, I bind rename-buffer to a key (and I use it fairly often). – Drew Apr 26 '17 at 14:04
  • @Drew I'm not sure if OP wants the technical "how to rename shell buffer" answer, or "what should I name shell buffer to make it unique / meaningfull" kind of answer (eg. Emacs will append <...> to buffer names if both are visiting a file with the same name based on some quite complex heuristic). In the later case, I don't quite have a good answer, but one possibility would be to update the name of the buffer using some meaningful part of the shell command ran in that buffer. – wvxvw Apr 26 '17 at 15:15
5

Go to the buffer you want to rename, in your case *shell*. Then type M-x rename-buffer and enter the new name for this buffer.

0

Add a function to your init.el, and create a keybinding:

(defun unique-shell ()
  (interactive)
  (shell)
  (rename-uniquely)
)

(global-set-key "\C-z"           'unique-shell)

Now every time you press ctrl+z, it will launch a shell with a new name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.