From 3f5e53a83cf8bc18d16e13364892a4bf71125837 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 13 Jan 2024 03:50:09 -0800 Subject: [PATCH] Some git prompt fixes --- init.el | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/init.el b/init.el index e3ad314..7825106 100644 --- a/init.el +++ b/init.el @@ -854,6 +854,7 @@ Take directly from doom-modeline." ;; eat (use-package eat + :bind ("C-c V" . my/project-eat-or-default) :config (defvar my/project-eat-hash-table (make-hash-table :test 'equal) "Hash table that maps project root dirs to eat buffers.") @@ -869,7 +870,7 @@ Take directly from doom-modeline." (let ((eat-buffer-name (concat "*eat for project " default-directory "*"))) (puthash default-directory (eat) - my/project-eaeat-hash-table))))) + my/project-eat-hash-table))))) (defun my/project-eat-or-default () "Open an eat for the current project, otherwise, open a normal eat." (interactive) @@ -925,6 +926,13 @@ If no name is given, list all bookmarks instead." (when my/eshell-bm-auto-ls (eshell/ls))) (eshell-print (string-join (bookmark-all-names) " ")))) + (defun my/-git-process-lines (&rest flags) + "Run `vc-git-program' and return an array of its output lines." + (with-temp-buffer + (apply 'vc-git-command t 0 nil flags) + (if (zerop (buffer-size)) + '() + (string-lines (buffer-substring-no-properties 1 (buffer-size)))))) (defun my/-replace-home-with-tilda (path) (let ((home (getenv "HOME"))) (if (equal home path) @@ -951,10 +959,10 @@ If no name is given, list all bookmarks instead." (my/-replace-home-with-tilda default-directory)))) (defun my/-eshell-prompt-status-char-for-branch (branch remote) "Get the status char representing the relation between BRANCH and REMOTE." - (let ((lines (process-lines vc-git-program - "rev-list" - "--left-right" - (concat branch "..." remote))) + (let ((lines (my/-git-process-lines + "rev-list" + "--left-right" + (concat branch "..." remote))) (to-remote nil) (to-local nil)) (dolist (line lines) @@ -969,10 +977,10 @@ If no name is given, list all bookmarks instead." (to-local ?󰜮)))) (defun my/-eshell-prompt-current-branch-status () "Get the status char for the current branch and its remote." - (let ((refs (process-lines vc-git-program - "for-each-ref" - "--format=%(HEAD)%00%(refname:short)%00%(upstream:short)" - "refs/heads"))) + (let ((refs (my/-git-process-lines + "for-each-ref" + "--format=%(HEAD)%00%(refname:short)%00%(upstream:short)" + "refs/heads"))) (catch 'break (dolist (ref refs) (if-let ((split-ref (split-string ref "\0" nil nil)) @@ -982,7 +990,7 @@ If no name is given, list all bookmarks instead." (caddr split-ref)))))))) (defun my/-eshell-prompt-git-state-chars () "Get chars, like + and ✘ for `my/-eshell-prompt-function'." - (let ((lines (process-lines vc-git-program "status" "--porcelain=v1")) + (let ((lines (my/-git-process-lines "status" "--porcelain=v1")) (branch-status (my/-eshell-prompt-current-branch-status)) (status-arr)) (dolist (line lines)