diff --git a/.emacs.d/lisp/init-eshell.el b/.emacs.d/lisp/init-eshell.el index 595d817e..0627d606 100644 --- a/.emacs.d/lisp/init-eshell.el +++ b/.emacs.d/lisp/init-eshell.el @@ -115,30 +115,31 @@ eshell-hist-ignoredups t eshell-destroy-buffer-when-process-dies t) -;;; Leave `eshell-highlight-prompt' to t as it sets the read-only property. -(setq eshell-prompt-function - (lambda nil - (let ((path (abbreviate-file-name (eshell/pwd)))) - (concat - (when ambrevar/eshell-status-p - (propertize (or (ambrevar/eshell-status-display) "") 'face font-lock-comment-face)) +(defun ambrevar/eshell-prompt () + (let ((path (abbreviate-file-name (eshell/pwd)))) + (concat + (when ambrevar/eshell-status-p + (propertize (or (ambrevar/eshell-status-display) "") 'face font-lock-comment-face)) + (format + (propertize "(%s@%s)" 'face '(:weight bold)) + (propertize (user-login-name) 'face '(:foreground "cyan")) + (propertize (system-name) 'face '(:foreground "cyan"))) + (if (and (require 'magit nil t) (or (magit-get-current-branch) (magit-get-current-tag))) + (let* ((prefix (abbreviate-file-name (magit-rev-parse "--show-prefix"))) + (before-prefix (substring-no-properties path nil (when (/= 0 (length prefix)) (- (length prefix)))))) (format - (propertize "(%s@%s)" 'face '(:weight bold)) - (propertize (user-login-name) 'face '(:foreground "cyan")) - (propertize (system-name) 'face '(:foreground "cyan"))) - (if (and (require 'magit nil t) (or (magit-get-current-branch) (magit-get-current-tag))) - (let* ((root (abbreviate-file-name (magit-rev-parse "--show-toplevel"))) - (after-root (substring-no-properties path (min (length path) (1+ (length root)))))) - (format - (propertize "[%s/%s@%s]" 'face '(:weight bold)) - (propertize root 'face `(:foreground ,(if (= (user-uid) 0) "orange" "gold"))) - (propertize after-root 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)) - (or (magit-get-current-branch) (magit-get-current-tag)))) - (format - (propertize "[%s]" 'face '(:weight bold)) - (propertize path 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)))) - (propertize "\n>" 'face '(:weight bold)) - " ")))) + (propertize "[%s/%s@%s]" 'face '(:weight bold)) + (propertize before-prefix 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)) + (propertize prefix 'face `(:foreground ,(if (= (user-uid) 0) "orange" "gold"))) + (or (magit-get-current-branch) (magit-get-current-tag)))) + (format + (propertize "[%s]" 'face '(:weight bold)) + (propertize path 'face `(:foreground ,(if (= (user-uid) 0) "red" "green") :weight bold)))) + (propertize "\n>" 'face '(:weight bold)) + " "))) + +;;; Leave `eshell-highlight-prompt' to t as it sets the read-only property. +(setq eshell-prompt-function #'ambrevar/eshell-prompt) ;;; If the prompt spans over multiple lines, the regexp should match ;;; last line only. (setq-default eshell-prompt-regexp "^> ")