From 14084271e9dd1ddb822a9415addf618a54f8021d Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Tue, 21 Jun 2022 17:03:11 -0700 Subject: feat(eshell): change the prompt to be like fish Change-Id: I8cfd546b668035ff3627cd0ac6a2082cd3d2dea8 --- emacs/custom/my-eshell.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'emacs') 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) -- cgit 1.4.1