Add ability to detect reverts to git prompt

This commit is contained in:
Alexander Rosenberg 2024-01-09 02:20:23 -08:00
parent b9852d2942
commit 9abf3bd469
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

14
init.el
View File

@ -914,14 +914,24 @@ If no name is given, list all bookmarks instead."
(when branch-status (when branch-status
(push branch-status status-arr)) (push branch-status status-arr))
(apply 'string status-arr))) (apply 'string status-arr)))
(defun my/-eshell-prompt-git-get-operation ()
"Return the current git operation. For example, a revert."
(let ((git-dir (expand-file-name ".git" (vc-git-root default-directory))))
(cond
((file-exists-p (expand-file-name "REVERT_HEAD" git-dir))
"REVERTING"))))
(defun my/-eshell-prompt-git-status () (defun my/-eshell-prompt-git-status ()
"Get git status for `my/-eshell-prompt-function'" "Get git status for `my/-eshell-prompt-function'"
(let ((branch (car (vc-git-branches))) (let ((branch (car (vc-git-branches)))
(state (my/-eshell-prompt-git-state-chars))) (state (my/-eshell-prompt-git-state-chars))
(operation (my/-eshell-prompt-git-get-operation)))
(concat (concat
(propertize (concat " 󰊢 " branch) 'face '(:foreground "medium purple")) (propertize (concat " 󰊢 " branch) 'face '(:foreground "medium purple"))
(unless (string-empty-p state) (unless (string-empty-p state)
(propertize (concat " [" state "]") 'face '(:foreground "red")))))) (propertize (concat " [" state "]") 'face '(:foreground "red")))
(when operation
(concat " (" (propertize operation 'face
'(:weight 'bold :foreground "yellow")) ")")))))
(defun my/-eshell-prompt-vc-status () (defun my/-eshell-prompt-vc-status ()
"Get vc status for `my/-eshell-prompt-function'." "Get vc status for `my/-eshell-prompt-function'."
(if-let (backend (vc-responsible-backend default-directory t)) (if-let (backend (vc-responsible-backend default-directory t))