From 071c77936fcdd8752421abd318abe5db5c36b068 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 28 May 2025 00:42:43 +0100 Subject: Add support for detached head in git repos for eshell-prompt --- Emacs/.config/emacs/elisp/eshell-prompt.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Emacs/.config/emacs') diff --git a/Emacs/.config/emacs/elisp/eshell-prompt.el b/Emacs/.config/emacs/elisp/eshell-prompt.el index d0a4e91..dafd8ea 100644 --- a/Emacs/.config/emacs/elisp/eshell-prompt.el +++ b/Emacs/.config/emacs/elisp/eshell-prompt.el @@ -79,18 +79,28 @@ number of files affected are returned in red." 'font-lock-face `(:foreground ,+eshell-prompt/failure-colour))))) +(defun +eshell-prompt/--git-branch-name () + (let* ((branch-name (thread-last + (split-string (shell-command-to-string "git branch") "\n") + (cl-remove-if (lambda (s) (= (length s) 0))) + (cl-find-if (lambda (s) (string= "*" (substring s 0 1)))))) + (branch-name (if (null branch-name) nil + (substring branch-name 2)))) + (cond + ((null branch-name) nil) + ((string= "(" (substring branch-name 0 1)) + (replace-regexp-in-string "\\(.*at \\)\\|)" "" branch-name)) + (t branch-name)))) + (defun +eshell-prompt/--git-status () "Returns a completely formatted string of form (BRANCH-NAME[REMOTE-STATUS])." - (let ((git-branch (thread-last - (split-string (shell-command-to-string "git branch") "\n") - (cl-remove-if (lambda (s) (= (length s) 0))) - (cl-find-if (lambda (s) (string= "*" (substring s 0 1))))))) + (let ((git-branch (+eshell-prompt/--git-branch-name))) (if (null git-branch) "" (format "(%s<%s>[%s])" - (nth 2 (split-string git-branch "\n\\|\\*\\| ")) + git-branch (+eshell-prompt/--git-change-status) (+eshell-prompt/--git-remote-status))))) -- cgit v1.2.3-13-gbd6f