Small utility functions that allow for fish-style trunctated directories in eshell and for example modeline.
shrink-path is available via MELPA (and MELPA Stable).
It can be installed by using M-x package-install RET shrink-path RET
inside Emacs or even better using use-package.
(use-package shrink-path
:ensure t
:demand t)
Configuration soon to be found in DOOM Emacs.
(setq eshell-prompt-regexp "^.* λ "
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)
(propertize " λ" 'face 'eshell-prompt-face)
;; needed for the input text to not have prompt face
(propertize " " 'face 'default))))
;; for completeness sake
(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) "]")
"")))