summary refs log tree commit diff
path: root/emacs/custom/my-eshell.el
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-21 17:03:11 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-21 17:05:23 -0700
commit14084271e9dd1ddb822a9415addf618a54f8021d (patch)
tree17baf0314787dfd7fa5aaf358859d8d1a2c5b9b1 /emacs/custom/my-eshell.el
parentfix(prog): use gofmt to format go code (diff)
downloademacs.d-14084271e9dd1ddb822a9415addf618a54f8021d.tar.gz
feat(eshell): change the prompt to be like fish
Change-Id: I8cfd546b668035ff3627cd0ac6a2082cd3d2dea8
Diffstat (limited to '')
-rw-r--r--emacs/custom/my-eshell.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/emacs/custom/my-eshell.el b/emacs/custom/my-eshell.el
index db2d540..bf9a0b4 100644
--- a/emacs/custom/my-eshell.el
+++ b/emacs/custom/my-eshell.el
@@ -138,6 +138,35 @@ append to it, while separating multiple outputs with
   (add-hook 'eshell-pre-command-hook #'my/eshell-current-command-start nil t)
   (add-hook 'eshell-post-command-hook #'my/eshell-current-command-stop nil t))
 
+(defun my/short-pwd (path)
+  "Turn a PATH of the form /foo/bar/baz into /f/b/baz, like fish shell."
+  (let* ((home-path (replace-regexp-in-string (expand-file-name "~")
+                                          "~"
+                                          path))
+         (current-dir (split-string home-path "/"))
+         (cdir (last current-dir))
+         (head (butlast current-dir)))
+    (concat (mapconcat (lambda (s)
+                         (if (string= "" s) nil
+                           (substring s 0 1)))
+                       head
+                       "/")
+            (if head "/" nil)
+            (car cdir))))
+
+(defmacro with-face (str &rest properties)
+  "Set the PROPERTIES for the given STR."
+  `(propertize ,str 'face (list ,@properties)))
+
+(defun my/prompt ()
+  "EShell prompt displaying VC info and such."
+  (concat
+   (with-face (concat (my/short-pwd (eshell/pwd)) " ") :foreground  "#070707")
+   (if (= 0 (user-uid))
+       (with-face "#" :foreground "#f43841")
+     (with-face "λ" :foreground "#63c904"))
+   (with-face " " :foreground "#000000")))
+
 (global-set-key (kbd "C-c e h") 'my/eshell-here)
 (define-key eshell-mode-map (kbd "C-c e e") 'my/eshell-export)
 (define-key eshell-mode-map (kbd "C-o") 'my/eshell-open-file-at-point)
@@ -148,6 +177,8 @@ append to it, while separating multiple outputs with
 (customize-set-variable 'eshell-save-history-on-exit t)
 (customize-set-variable 'eshell-cd-on-directory t)
 (customize-set-variable 'eshell-prefer-lisp-functions nil)
+(customize-set-variable 'eshell-prompt-function 'my/prompt)
+(customize-set-variable 'eshell-highlight-prompt nil)
 (customize-set-variable 'eshell-where-to-jump 'begin)
 (customize-set-variable 'eshell-review-quick-commands nil)
 (customize-set-variable 'eshell-smart-space-goes-to-end t)