Eshell: Fix prompt fontification of symlinks inside Git repositories

master
Pierre Neidhardt 2018-10-17 14:36:13 +02:00
parent 3e45f23179
commit 479ae9adab
1 changed files with 24 additions and 23 deletions

View File

@ -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 "^> ")