From e07c2c145722c3fd29d2eec6e5c665b1f3ac8acd Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 16 Apr 2024 21:52:07 +0630 Subject: (Emacs/app)~Made eshell prompt a bit cooler Now it shows if the worktree is unclean and how many commits ahead or behind we are from the remote (if one is set). --- Emacs/.config/emacs/app.org | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'Emacs/.config/emacs/app.org') diff --git a/Emacs/.config/emacs/app.org b/Emacs/.config/emacs/app.org index 61ca240..ce47e23 100644 --- a/Emacs/.config/emacs/app.org +++ b/Emacs/.config/emacs/app.org @@ -455,17 +455,39 @@ much faster than ~cd ..; ls -l~). #+begin_src emacs-lisp (use-package eshell :config + (defun +eshell/--git-get-remote-status () + (let* ((branch-status (split-string + (shell-command-to-string "git status | grep 'Your branch is'"))) + (status (nth 3 branch-status)) + (diff (cl-position "by" branch-status :test #'string=))) + (if (null diff) + (propertize "=" 'font-lock-face '(:foreground "green")) + (let ((n (nth (+ 1 diff) branch-status))) + (concat + (cond + ((string= status "ahead") + (propertize "→ " 'font-lock-face '(:foreground "dodger blue"))) + ((string= status "behind") + (propertize "← " 'font-lock-face '(:foreground "orange red")))) + n))))) + + (defun +eshell/--git-get-change-status () + (let ((changed-files (- (length (split-string (shell-command-to-string "git status -s" ) "\n")) 1))) + (if (= changed-files 0) + (propertize "✓" 'font-lock-face '(:foreground "green")) + (propertize (number-to-string changed-files) 'font-lock-face '(:foreground "red"))))) + (defun +eshell/get-git-properties () (let ((git-branch (shell-command-to-string "git branch"))) (if (or (string= git-branch "") (not (string= "*" (substring git-branch 0 1)))) "" (format - "(%s<%s>)" + "(%s<%s>[%s])" (nth 2 (split-string git-branch "\n\\|\\*\\| ")) - (if (string= "" (shell-command-to-string "git status | grep 'up to date'")) - (propertize "×" 'font-lock-face '(:foreground "red")) - (propertize "✓" 'font-lock-face '(:foreground "green"))))))) + (+eshell/--git-get-change-status) + (+eshell/--git-get-remote-status))))) + (defun +eshell/prompt-function () (let ((git (+eshell/get-git-properties))) (mapconcat -- cgit v1.2.3-13-gbd6f