Compare commits
2 Commits
47039d4bfe
...
7310a981e7
Author | SHA1 | Date | |
---|---|---|---|
7310a981e7 | |||
3d84c322bb |
@ -62,49 +62,83 @@ STATUS-LINE is the first line of output from \"git status --porcelain=v1 -b\"."
|
|||||||
|
|
||||||
(defun eshell-starship--prompt-git-has-stash ()
|
(defun eshell-starship--prompt-git-has-stash ()
|
||||||
"Return t if the current git directory has a stash, nil otherwise."
|
"Return t if the current git directory has a stash, nil otherwise."
|
||||||
(= (process-file vc-git-program nil nil nil
|
(zerop (process-file vc-git-program nil nil nil
|
||||||
"rev-parse" "--verify" "refs/stash") 0))
|
"rev-parse" "--verify" "refs/stash")))
|
||||||
|
|
||||||
(defun eshell-starship--prompt-git-state-chars ()
|
(defun eshell-starship--prompt-git-state-chars ()
|
||||||
"Get chars, like + and ✘ for `eshell-starship--prompt-function'."
|
"Get chars, like + and ✘ for `eshell-starship--prompt-function'."
|
||||||
(let* ((lines (eshell-starship--git-process-lines "status" "--porcelain=v1" "-b"))
|
(with-temp-buffer
|
||||||
(branch-status (eshell-starship--prompt-current-branch-status
|
(when (zerop (vc-git-command t nil nil "status" "--porcelain=v1" "-b"))
|
||||||
(car lines)))
|
(goto-char (point-min))
|
||||||
(status-arr))
|
(cl-loop with command-error-function = nil
|
||||||
(dolist (line (cdr lines))
|
with status-arr = nil
|
||||||
(cl-loop with fields = (string-split line " " t " *")
|
with first-line = (buffer-substring-no-properties
|
||||||
with status-str = (car-safe fields)
|
(point) (pos-eol))
|
||||||
for status-char across status-str
|
;; account for newline at end
|
||||||
|
with line-count = (car (buffer-line-statistics))
|
||||||
|
with cur-buf = (current-buffer)
|
||||||
|
do (forward-line)
|
||||||
|
for x_status = (char-after)
|
||||||
|
for y_status = (char-after (1+ (point)))
|
||||||
|
until (> (line-number-at-pos) line-count)
|
||||||
do
|
do
|
||||||
(cond ((or (= status-char ?M) (= status-char ?T))
|
(cond
|
||||||
(push ?! status-arr))
|
((or (= ?D x_status y_status)
|
||||||
((= status-char ??)
|
(= ?A x_status y_status)
|
||||||
(push ?? status-arr))
|
(= ?U x_status y_status)
|
||||||
((or (= status-char ?A) (= status-char ?C))
|
(and (= ?A x_status) (= ?U y_status))
|
||||||
(push ?+ status-arr))
|
(and (= ?U x_status) (= ?D y_status))
|
||||||
((= status-char ?D)
|
(and (= ?U x_status) (= ?A y_status))
|
||||||
(push ? status-arr))
|
(and (= ?D x_status) (= ?U y_status)))
|
||||||
((= status-char ?R)
|
(push ?= status-arr))
|
||||||
(push ?» status-arr))
|
((or (= x_status ?D) (= y_status ?D))
|
||||||
((= status-char ?U)
|
(push ? status-arr))
|
||||||
(push ?= status-arr)))))
|
((or (= x_status ?R) (= y_status ?R))
|
||||||
(when (eshell-starship--prompt-git-has-stash)
|
(push ?» status-arr))
|
||||||
(push ?$ status-arr))
|
((= y_status ?M)
|
||||||
(sort status-arr #'<)
|
(push ?! status-arr))
|
||||||
(when branch-status
|
((or (= x_status ?A) (= x_status ?M))
|
||||||
(push branch-status status-arr))
|
(push ?+ status-arr))
|
||||||
(apply 'string (seq-uniq status-arr))))
|
((= x_status y_status ??)
|
||||||
|
(push ?? status-arr)))
|
||||||
|
finally
|
||||||
|
(sort status-arr #'(lambda (a b)
|
||||||
|
(cond
|
||||||
|
((= a ?=)
|
||||||
|
t)
|
||||||
|
((= b ?=)
|
||||||
|
nil)
|
||||||
|
(t
|
||||||
|
(< a b)))))
|
||||||
|
(when (eshell-starship--prompt-git-has-stash)
|
||||||
|
(if (= (car status-arr) ?=)
|
||||||
|
(setq status-arr (append '(?= ?$) (cdr status-arr)))
|
||||||
|
(push ?$ status-arr)))
|
||||||
|
(when-let (branch-status (eshell-starship--prompt-current-branch-status
|
||||||
|
first-line))
|
||||||
|
(push branch-status status-arr))
|
||||||
|
finally return (apply 'string (seq-uniq status-arr))))))
|
||||||
|
|
||||||
(defun eshell-starship--prompt-git-get-operation ()
|
(defun eshell-starship--prompt-git-get-operation ()
|
||||||
"Return the current git operation. For example, a revert."
|
"Return the current git operation. For example, a revert."
|
||||||
(let ((git-dir (expand-file-name ".git" (vc-git-root default-directory))))
|
(let ((git-dir (expand-file-name ".git" (vc-git-root default-directory))))
|
||||||
(cond
|
(cond
|
||||||
((file-exists-p (expand-file-name "REVERT_HEAD" git-dir))
|
((file-exists-p (expand-file-name "rebase-apply/applying" git-dir))
|
||||||
"REVERTING")
|
"AM")
|
||||||
|
((file-exists-p (expand-file-name "rebase-apply/rebasing" git-dir))
|
||||||
|
"REBASE")
|
||||||
|
((file-exists-p (expand-file-name "rebase-apply" git-dir))
|
||||||
|
"AM/REBASE")
|
||||||
((file-exists-p (expand-file-name "rebase-merge" git-dir))
|
((file-exists-p (expand-file-name "rebase-merge" git-dir))
|
||||||
"REBASING")
|
"REBASING")
|
||||||
|
((file-exists-p (expand-file-name "CHERRY_PICK_HEAD" git-dir))
|
||||||
|
"CHERRY-PICKING")
|
||||||
((file-exists-p (expand-file-name "MERGE_HEAD" git-dir))
|
((file-exists-p (expand-file-name "MERGE_HEAD" git-dir))
|
||||||
"MERGING"))))
|
"MERGING")
|
||||||
|
((file-exists-p (expand-file-name "BISECT_LOG" git-dir))
|
||||||
|
"BISECTING")
|
||||||
|
((file-exists-p (expand-file-name "REVERT_HEAD" git-dir))
|
||||||
|
"REVERTING"))))
|
||||||
|
|
||||||
(defun eshell-starship--prompt-git-status ()
|
(defun eshell-starship--prompt-git-status ()
|
||||||
"Get git status for `eshell-starship--prompt-function'."
|
"Get git status for `eshell-starship--prompt-function'."
|
||||||
|
3
init.el
3
init.el
@ -110,6 +110,9 @@
|
|||||||
;; Set fonts
|
;; Set fonts
|
||||||
(add-to-list 'default-frame-alist '(font . "FiraCode Nerd Font Mono-12"))
|
(add-to-list 'default-frame-alist '(font . "FiraCode Nerd Font Mono-12"))
|
||||||
|
|
||||||
|
;; For source lookups
|
||||||
|
(setq find-function-C-source-directory "~/src/emacs/src/")
|
||||||
|
|
||||||
;; Some settings for programming
|
;; Some settings for programming
|
||||||
(setq-default indent-tabs-mode nil
|
(setq-default indent-tabs-mode nil
|
||||||
tab-width 4
|
tab-width 4
|
||||||
|
Loading…
Reference in New Issue
Block a user