[emacs] customize the eshell prompt
authorAmin Bandali <bandali@gnu.org>
Mon, 12 Nov 2018 03:47:57 +0000 (22:47 -0500)
committerAmin Bandali <bandali@gnu.org>
Mon, 12 Nov 2018 03:49:02 +0000 (22:49 -0500)
adapted from https://gitlab.com/bennya/shrink-path.el

init.org

index d4da17d..127926d 100644 (file)
--- a/init.org
+++ b/init.org
@@ -1782,6 +1782,37 @@ Hopefully temporary.
   (global-hl-todo-mode))
 #+end_src
 
+** shrink-path
+
+#+begin_src emacs-lisp
+(use-package shrink-path
+  :after eshell
+  :config
+  (setq eshell-prompt-regexp "\\(.*\n\\)*λ "
+        eshell-prompt-function #'+eshell/prompt)
+
+  (defun +eshell/prompt ()
+    (let ((base/dir (shrink-path-prompt default-directory)))
+      (concat (propertize (car base/dir)
+                          'face 'font-lock-comment-face)
+              (propertize (cdr base/dir)
+                          'face 'font-lock-constant-face)
+              (propertize (+eshell--current-git-branch)
+                          'face 'font-lock-function-name-face)
+              "\n"
+              (propertize "λ" 'face 'eshell-prompt-face)
+              ;; needed for the input text to not have prompt face
+              (propertize " " 'face 'default))))
+
+  (defun +eshell--current-git-branch ()
+    (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
+                             when (string-match "^\*" match)
+                             collect match))))
+      (if (not (eq branch nil))
+          (concat " " (substring branch 2))
+        ""))))
+#+end_src
+
 * Email
 
 #+begin_src emacs-lisp