Friday afternoon. Thought I’d share this which I’ve been using for
a year or two.
Imagine your viewing a remote file on example.com, via tramp of course.
If you do M-x shell you get a new buffer with an interactive shell.
The code below will bless this new shell buffer with a nicer name,
e.g. *shell:example.com* instead of say *shell*.
```
(defun auto-name-shell-buffers (original-shell-fn &optional
buffer)
"Wrap ORIGINAL-SHELL-FN to avoid tramp shell buffers name
*shell*, do nothing if BUFFER."
(cond
((or buffer
(not (tramp-tramp-file-p default-directory)))
(funcall original-shell-fn buffer))
((not (zerop (call-process "/usr/bin/ssh-add" nil nil nil
"-l")))
(message "ssh auth socket is bork'd"))
(t
(with-parsed-tramp-file-name default-directory tp
(let* ( ; (tramp-path (tramp-dissect-file-name
default-directory))
(host (tramp-file-name-host tp))
(user (if (tramp-file-name-user tp)
(format "%s@" (tramp-file-name-user tp))
""))
(new-buffer-name (format "*shell:%s%s*" user host)))
(funcall original-shell-fn new-buffer-name))))))
(advice-add 'shell :around #'auto-name-shell-buffers)
```
No doubt other crafts people would write this in far more elegant ways.
Feel free to provide feedback.
For example I don’t recall how I determined that (tramp-tramp-file-p
directory)
was a fine way to tell if the current buffer is leveraging tramp.
- ben
ps. The cond clause that checks for a valid ssh agent can be removed.
I always have an agent, so I like it.
_______________________________________________
Tramp-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/tramp-devel