Compare commits

...

3 Commits

Author SHA1 Message Date
2b7960d427
Do not rely on / file separator in eshell git prompt 2022-08-30 19:09:10 +02:00
263d1af073
Try to avoid eshell git prompt calls when inside a git directory
Not sure whether this is really the right way to do it.
2022-08-30 19:06:32 +02:00
437ce6daff
Fix errors in eshell prompt function
To determine whether a merge is in progress, do not check in the current
directory for .git/MERGE_HEAD, but do this in the repository directory.

When computing `base-dir`, take the whole non-directory part, not just the
basename; otherwise directories like .emacs.d will get the final `.d` get
stripped off.
2022-08-30 18:51:29 +02:00

View File

@ -74,28 +74,35 @@ git repository."
(when (and (not (file-remote-p pwd))
(eshell-search-path "git")
(setq repo-dir (locate-dominating-file pwd ".git")))
(if (string-prefix-p (file-truename (file-name-concat repo-dir ".git"))
(file-truename pwd))
"GIT_DIR"
(save-match-data
(let* ((git-branch (string-trim
(shell-command-to-string "git rev-parse --abbrev-ref HEAD")))
(base-dir (file-name-base (string-trim-right repo-dir "/?")))
(state-list (cl-remove-if #'null
(list
(when (file-exists-p (file-name-concat "." ".git" "MERGE_HEAD"))
"merge")
(base-dir (file-name-nondirectory (directory-file-name repo-dir)))
state-list)
(when (file-exists-p (file-name-concat repo-dir ".git" "MERGE_HEAD"))
(push "merge" state-list))
(when (= 1 (call-process "git" nil nil nil
"diff" "--no-ext-diff" "--quiet" "--exit-code"))
"dirty")
(push "dirty" state-list))
(when (= 1 (call-process "git" nil nil nil
"diff" "--no-ext-diff" "--quiet" "--exit-code" "--cached"))
"uncommitted")
(push "uncommitted" state-list))
(when (with-temp-buffer
(and (= 0 (call-process "git" nil t nil
"stash" "list"))
(not (= 0 (buffer-size)))))
"stash")))))
(push "stash" state-list))
(if state-list
(format "%s@%s[%s]" git-branch base-dir (apply #'concat (-interpose "|" state-list)))
(format "%s@%s" git-branch base-dir)))))))
(format "%s@%s" git-branch base-dir))))))))
(defun eshell/default-prompt-function ()
"A prompt for eshell of the form