From c86fb72bb100fb2cdc81ac5d30b71fe4d1ab7a1e Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 17 Oct 2021 18:15:37 -0700 Subject: emacs: different prompt when on a remote host Replace the prompt with `@' when our current eshell path is on a remote host. --- emacs/custom/fcuny-eshell.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el index 38d67da..c5523ce 100644 --- a/emacs/custom/fcuny-eshell.el +++ b/emacs/custom/fcuny-eshell.el @@ -76,10 +76,14 @@ length of PATH (sans directory slashes) down to MAX-LEN." (concat str (cl-reduce (lambda (a b) (concat a "/" b)) components)))) (defun fcuny/eshell-prompt () - (setq eshell-prompt-regexp "; ") + "Sets the prompt for eshell. If the current path is on a remote +host and starts with `ssh:', then we replace the prompt with +`@' to indicate we're on a remote host." (concat - (concat (system-name) ":") - (fcuny/shorten-path (eshell/pwd)) + (let ((absolute-path (eshell/pwd))) + (if (string-match "/ssh:\\(.+\\):" absolute-path) + (replace-match (concat "@" (match-string 1 absolute-path) " ") nil nil absolute-path) + (fcuny/shorten-path absolute-path))) "; ")) (defun fcuny/eshell-here () -- cgit 1.4.1