Allow to customize whether the eshell prompt contains the git state
Since all of this is slow on Windows, it's better to be able to disable it. Sigh.
This commit is contained in:
parent
2b7960d427
commit
8b97b092c4
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'db-customize)
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
(require 'subr-x)
|
(require 'subr-x)
|
||||||
(require 'seq)
|
(require 'seq)
|
||||||
|
@ -54,6 +55,19 @@
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(eshell-send-input)))
|
(eshell-send-input)))
|
||||||
|
|
||||||
|
(defcustom db/eshell-prompt-include-git-state (if (member system-type '(windows-nt cygwin)) nil t)
|
||||||
|
"Whether to include git state information in the eshell prompt.
|
||||||
|
|
||||||
|
State information includes whether the worktree is dirty, whether
|
||||||
|
the index contains uncommitted changes, whether a merge is in
|
||||||
|
progress and whether the stash stack is non-empty.
|
||||||
|
|
||||||
|
Including this in the prompt might be slow on certain
|
||||||
|
systems (looking at you, Windows) and may thus not be desirable.
|
||||||
|
Set to nil to disable."
|
||||||
|
:group 'personal-settings
|
||||||
|
:type '(choice (const nil) (const t)))
|
||||||
|
|
||||||
(defun db/eshell-git-branch-string ()
|
(defun db/eshell-git-branch-string ()
|
||||||
;; Inspired by https://github.com/howardabrams/dot-files/blob/master/emacs-eshell.org#special-prompt
|
;; Inspired by https://github.com/howardabrams/dot-files/blob/master/emacs-eshell.org#special-prompt
|
||||||
"Return name of git branch of current directory, as a string.
|
"Return name of git branch of current directory, as a string.
|
||||||
|
@ -83,22 +97,24 @@ git repository."
|
||||||
(base-dir (file-name-nondirectory (directory-file-name repo-dir)))
|
(base-dir (file-name-nondirectory (directory-file-name repo-dir)))
|
||||||
state-list)
|
state-list)
|
||||||
|
|
||||||
(when (file-exists-p (file-name-concat repo-dir ".git" "MERGE_HEAD"))
|
(when db/eshell-prompt-include-git-state
|
||||||
(push "merge" state-list))
|
|
||||||
|
|
||||||
(when (= 1 (call-process "git" nil nil nil
|
(when (file-exists-p (file-name-concat repo-dir ".git" "MERGE_HEAD"))
|
||||||
"diff" "--no-ext-diff" "--quiet" "--exit-code"))
|
(push "merge" state-list))
|
||||||
(push "dirty" state-list))
|
|
||||||
|
|
||||||
(when (= 1 (call-process "git" nil nil nil
|
(when (= 1 (call-process "git" nil nil nil
|
||||||
"diff" "--no-ext-diff" "--quiet" "--exit-code" "--cached"))
|
"diff" "--no-ext-diff" "--quiet" "--exit-code"))
|
||||||
(push "uncommitted" state-list))
|
(push "dirty" state-list))
|
||||||
|
|
||||||
(when (with-temp-buffer
|
(when (= 1 (call-process "git" nil nil nil
|
||||||
(and (= 0 (call-process "git" nil t nil
|
"diff" "--no-ext-diff" "--quiet" "--exit-code" "--cached"))
|
||||||
"stash" "list"))
|
(push "uncommitted" state-list))
|
||||||
(not (= 0 (buffer-size)))))
|
|
||||||
(push "stash" state-list))
|
(when (with-temp-buffer
|
||||||
|
(and (= 0 (call-process "git" nil t nil
|
||||||
|
"stash" "list"))
|
||||||
|
(not (= 0 (buffer-size)))))
|
||||||
|
(push "stash" state-list)))
|
||||||
|
|
||||||
(if state-list
|
(if state-list
|
||||||
(format "%s@%s[%s]" git-branch base-dir (apply #'concat (-interpose "|" state-list)))
|
(format "%s@%s[%s]" git-branch base-dir (apply #'concat (-interpose "|" state-list)))
|
||||||
|
|
Loading…
Reference in New Issue