(Emacs/elisp)~variables for colours of success, failure and dir in eshell-prompt

This commit is contained in:
2024-09-08 02:59:58 +01:00
parent 4739f8798f
commit 6145df8c49

View File

@@ -27,11 +27,15 @@
(defvar +eshell-prompt/user-prompt "𝜆> " (defvar +eshell-prompt/user-prompt "𝜆> "
"Prompt for user to input.") "Prompt for user to input.")
(defvar +eshell-prompt/dir-colour "forestgreen")
(defvar +eshell-prompt/success-colour "forestgreen")
(defvar +eshell-prompt/failure-colour "red")
(defun +eshell-prompt/--colour-on-last-command () (defun +eshell-prompt/--colour-on-last-command ()
"Returns an Emacs colour based on ESHELL-LAST-COMMAND-STATUS." "Returns an Emacs colour based on ESHELL-LAST-COMMAND-STATUS."
(if (zerop eshell-last-command-status) (if (zerop eshell-last-command-status)
"forestgreen" +eshell-prompt/success-colour
"darkred")) +eshell-prompt/failure-colour))
(defun +eshell-prompt/--git-remote-status () (defun +eshell-prompt/--git-remote-status ()
"Returns a propertized string for the status of a repository "Returns a propertized string for the status of a repository
@@ -49,14 +53,14 @@ behind or ahead the local repository is."
(status (nth 3 branch-status)) (status (nth 3 branch-status))
(diff (cl-position "by" branch-status :test #'string=))) (diff (cl-position "by" branch-status :test #'string=)))
(if (null diff) (if (null diff)
(propertize "=" 'font-lock-face '(:foreground "green")) (propertize "=" 'font-lock-face `(:foreground ,+eshell-prompt/success-colour))
(let ((n (nth (+ 1 diff) branch-status))) (let ((n (nth (+ 1 diff) branch-status)))
(concat (concat
(cond (cond
((string= status "ahead") ((string= status "ahead")
(propertize "" 'font-lock-face '(:foreground "dodger blue"))) (propertize "" 'font-lock-face '(:foreground "dodger blue")))
((string= status "behind") ((string= status "behind")
(propertize "" 'font-lock-face '(:foreground "orange red")))) (propertize "" 'font-lock-face '(:foreground "red"))))
n))))) n)))))
(defun +eshell-prompt/--git-change-status () (defun +eshell-prompt/--git-change-status ()
@@ -68,8 +72,12 @@ number of files affected are returned in red."
(command-output (split-string (shell-command-to-string git-cmd) "\n")) (command-output (split-string (shell-command-to-string git-cmd) "\n"))
(changed-files (- (length command-output) 1))) (changed-files (- (length command-output) 1)))
(if (= changed-files 0) (if (= changed-files 0)
(propertize "" 'font-lock-face '(:foreground "green")) (propertize ""
(propertize (number-to-string changed-files) 'font-lock-face '(:foreground "red"))))) 'font-lock-face
`(:foreground ,+eshell-prompt/success-colour))
(propertize (number-to-string changed-files)
'font-lock-face
`(:foreground ,+eshell-prompt/failure-colour)))))
(defun +eshell-prompt/--git-status () (defun +eshell-prompt/--git-status ()
"Returns a completely formatted string of "Returns a completely formatted string of
@@ -97,7 +105,7 @@ form (BRANCH-NAME<CHANGES>[REMOTE-STATUS])."
item)) item))
(list (list
"[" "["
`(,(abbreviate-file-name (eshell/pwd)) :foreground "LimeGreen") `(,(abbreviate-file-name (eshell/pwd)) :foreground ,+eshell-prompt/dir-colour)
"]" "]"
(if (string= git "") (if (string= git "")
"" ""