From 2d52241d459c8d59d5625a52c01755b692bb9e12 Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Thu, 3 Oct 2024 20:43:17 -0500 Subject: [PATCH] Adding a fancy prompt for eshell. --- .config/emacs/config.el | 23 +++++++++++------- .config/emacs/config.org | 12 +++++----- .config/emacs/scripts/eshell-prompt.el | 33 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 .config/emacs/scripts/eshell-prompt.el diff --git a/.config/emacs/config.el b/.config/emacs/config.el index 7160b78..ac88b1b 100644 --- a/.config/emacs/config.el +++ b/.config/emacs/config.el @@ -1,8 +1,9 @@ (add-to-list 'load-path "~/.config/emacs/scripts/") (require 'elpaca-setup) ;; The Elpaca Package Manager -(require 'buffer-move) ;; Buffer-move for better window management (require 'app-launchers) ;; Use emacs as a run launcher like dmenu (experimental) +(require 'buffer-move) ;; Buffer-move for better window management +(require 'eshell-prompt) ;; A fancy prompt for eshell (use-package all-the-icons :ensure t @@ -568,14 +569,14 @@ (eval-after-load 'org-indent '(diminish 'org-indent-mode)) -(custom-set-faces - '(org-level-1 ((t (:inherit outline-1 :height 1.7)))) - '(org-level-2 ((t (:inherit outline-2 :height 1.6)))) - '(org-level-3 ((t (:inherit outline-3 :height 1.5)))) - '(org-level-4 ((t (:inherit outline-4 :height 1.4)))) - '(org-level-5 ((t (:inherit outline-5 :height 1.3)))) - '(org-level-6 ((t (:inherit outline-5 :height 1.2)))) - '(org-level-7 ((t (:inherit outline-5 :height 1.1))))) + (custom-set-faces + '(org-level-1 ((t (:inherit outline-1 :height 1.7)))) + '(org-level-2 ((t (:inherit outline-2 :height 1.6)))) + '(org-level-3 ((t (:inherit outline-3 :height 1.5)))) + '(org-level-4 ((t (:inherit outline-4 :height 1.4)))) + '(org-level-5 ((t (:inherit outline-5 :height 1.3)))) + '(org-level-6 ((t (:inherit outline-5 :height 1.2)))) + '(org-level-7 ((t (:inherit outline-5 :height 1.1))))) (require 'org-tempo) @@ -655,6 +656,10 @@ (setq use-dialog-box nil) ;; No dialog box (setq pop-up-windows nil) ;; No popup windows +(setopt eshell-prompt-function 'fancy-shell) +(setopt eshell-prompt-regexp "^[^#$\n]* [$#] ") +(setopt eshell-highlight-prompt nil) + (use-package eshell-toggle :custom (eshell-toggle-size-fraction 3) diff --git a/.config/emacs/config.org b/.config/emacs/config.org index 777aa4b..cebd61e 100644 --- a/.config/emacs/config.org +++ b/.config/emacs/config.org @@ -1,9 +1,4 @@ -<<<<<<< HEAD - #+TITLE: DT's GNU Emacs Config -======= -+TITLE: DT's GNU Emacs Config ->>>>>>> 5ea1b34d7a73b295c19ecae4d963083c5ffac771 #+AUTHOR: Derek Taylor (DT) #+DESCRIPTION: DT's personal Emacs config. #+STARTUP: showeverything @@ -75,8 +70,9 @@ To keep this =config.org= a reasonable length, I have moved a lot of code to ind ** Sourcing the scripts #+begin_src emacs-lisp (require 'elpaca-setup) ;; The Elpaca Package Manager -(require 'buffer-move) ;; Buffer-move for better window management (require 'app-launchers) ;; Use emacs as a run launcher like dmenu (experimental) +(require 'buffer-move) ;; Buffer-move for better window management +(require 'eshell-prompt) ;; A fancy prompt for eshell #+end_src * ALL THE ICONS @@ -956,6 +952,10 @@ In my configs, all of my shells (bash, fish, zsh and the ESHELL) require my shel Eshell is an Emacs 'shell' that is written in Elisp. #+begin_src emacs-lisp +(setopt eshell-prompt-function 'fancy-shell) +(setopt eshell-prompt-regexp "^[^#$\n]* [$#] ") +(setopt eshell-highlight-prompt nil) + (use-package eshell-toggle :custom (eshell-toggle-size-fraction 3) diff --git a/.config/emacs/scripts/eshell-prompt.el b/.config/emacs/scripts/eshell-prompt.el new file mode 100644 index 0000000..8b1495e --- /dev/null +++ b/.config/emacs/scripts/eshell-prompt.el @@ -0,0 +1,33 @@ +;;; eshell-prompt.el --- a fancy shell prompt for eshell + +;;; Code: + +;; fancy-shell +;; A fancy shell prompt for eshell. + +(defun fancy-shell () + "A pretty shell with git status" + (let* ((cwd (abbreviate-file-name (eshell/pwd))) + (ref (magit-get-shortname "HEAD")) + (stat (magit-file-status)) + (x-stat eshell-last-command-status) + (git-chunk + (if ref + (format "%s%s%s " + (propertize (if stat "[" "(") 'font-lock-face (list :foreground (if stat "#e81050" "#9bee8b"))) + (propertize ref 'font-lock-face '(:foreground "#c897ff")) + (propertize (if stat "]" ")") 'font-lock-face (list :foreground (if stat "#e81050" "#9bee8b")))) + ""))) + (propertize + (format "%s %s %s$ " + (if (< 0 x-stat) (format (propertize "!%s" 'font-lock-face '(:foreground "#e81050")) x-stat) + (propertize "➤" 'font-lock-face (list :foreground (if (< 0 x-stat) "#e81050" "#9bee8b")))) + (propertize cwd 'font-lock-face '(:foreground "#45babf")) + git-chunk) + 'read-only t + 'front-sticky '(font-lock-face read-only) + 'rear-nonsticky '(font-lock-face read-only)))) + + +(provide 'eshell-prompt) +;;; eshell-prompt.el ends here