Skip to content

Instantly share code, notes, and snippets.

@dove-young
Created May 9, 2013 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dove-young/5547665 to your computer and use it in GitHub Desktop.
Save dove-young/5547665 to your computer and use it in GitHub Desktop.
Rename shell-mode buffer to the destination host-name in SSH login Emacs natively support rename shell-mode buffer by appending numbers in each buffer. But it does not make any sense. I used to login to many different machines through Emacs shell-mode, so I'd like to have buffer name represent the host-name I am working on. Just like what many t…
(setq shell-buffer-name-list (list "*shell*") )
(defun rename-buffer-in-ssh-login (cmd)
"Rename buffer to the destination hostname in ssh login"
(if (string-match "ssh .* [-_a-z0-9A-Z]+@[-_a-z0-9A-Z.]+[ ]*[^-_a-z0-9-A-Z.]*$" cmd)
(let (( host (nth 1 (split-string cmd "[@\n]" t) ))
)
(rename-buffer (concat "*" host))
(add-to-list 'shell-buffer-name-list (concat "*" host))
(message "%s" shell-buffer-name-list)
)
)
)
(add-hook 'comint-input-filter-functions 'rename-buffer-in-ssh-login)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment