From 41ac1061ffd2f26bafbda8619bf9599370404c62 Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Sun, 17 Jul 2022 13:35:17 -0800 Subject: [PATCH] Eshell prompt --- lisp/eshell-settings.el | 42 +++++++++++++++++++++++++++++++++++------ lisp/mitch-packages.el | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lisp/eshell-settings.el b/lisp/eshell-settings.el index be38458..3361dff 100644 --- a/lisp/eshell-settings.el +++ b/lisp/eshell-settings.el @@ -14,18 +14,48 @@ This is taken from a website that I can't remember at the moment." #'find-file-other-window (mapcar #'expand-file-name (eshell-flatten-list (reverse args)))))) + (defun eshell/clear () "Clear the scrollback buffer, like `clear' in a real shell..." (eshell/clear-scrollback)) + (defun eshell/faketty (&rest args) "USAGE: `faketty ARGS` where ARGS is anything that spews colors. Credit: https://stackoverflow.com/questions/1401002/how-to-trick-an-application-into-thinking-its-stdout-is-a-terminal-not-a-pipe" - (let - ((shell-command-dont-erase-buffer t)) - (shell-command - (concat "script -qfc '" args "' /dev/null") - (current-buffer)) - )) + (shell-command-to-string + (format "script -qfc %s /dev/null" args))) + +(defun with-face (str &rest face-plist) + (propertize str 'face face-plist)) +(defun custom-eshell-prompt () + (let* ( + ;; Get the git branch. + (git-branch-unparsed + (shell-command-to-string "git rev-parse --abbrev-ref HEAD 2>/dev/null")) + (git-branch + (if (string= git-branch-unparsed "") + "" + ;; Remove the trailing newline. + (substring git-branch-unparsed 0 -1))) + ) + (concat + ;; Timestamp. + ;; (with-face + ;; (format-time-string "[%a, %b %d | %H:%M:%S]\n" (current-time)) + ;; :inherit font-lock-builtin-face) + ;; Directory. + (with-face (concat (airline-shorten-directory default-directory (/ (window-width) 2)) " ") :inherit font-lock-constant-face) + ;; Git branch. + (unless (string= git-branch "") + (with-face (concat "[" git-branch "]") :inherit font-lock-string-face)) + "\n" + ;; Prompt. + ;; NOTE: Need to keep " $" for the next/previous prompt regexp to work. + (with-face ">" :inherit font-lock-preprocessor-face) + " " + ))) +(setq eshell-prompt-function 'custom-eshell-prompt) +(setq eshell-highlight-prompt nil) (provide 'eshell-settings) ;;; eshell-settings.el ends here diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index b84cb8a..a54f6c0 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -286,7 +286,7 @@ :custom (airline-cursor-colors nil) (airline-display-directory t) - (airline-eshell-colors t) + (airline-eshell-colors nil) (airline-shortened-directory-length 20) (airline-utf-glyph-separator-left 9585) (airline-utf-glyph-separator-right 9586)