summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-12-28 16:45:38 +0200
committerThanos Apollo <[email protected]>2024-12-28 16:45:38 +0200
commit237a00e847ff9157659531faeec7e1af3ee349a1 (patch)
tree8e50886f8e04fda37569384a9f13be04850b56eb
parent34e204e5ddb51384405743c06639abe435eff6b3 (diff)
emacs: Rewrite eshell configuration.
-rw-r--r--.config/emacs/init.el31
1 files changed, 28 insertions, 3 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el
index 77ef8ea..87fcde8 100644
--- a/.config/emacs/init.el
+++ b/.config/emacs/init.el
@@ -649,10 +649,35 @@
(completion-preview-insert)
(delete-char -1))
-(use-package eshell
- :ensure t
+(use-package esh-mode
+ :ensure nil
:config
- (setf eshell-highlight-prompt t)
+ (defun eshell/git-info ()
+ "Return a string with Git information if in a Git repository, or nil otherwise."
+ (when (eq (call-process "git" nil nil nil "rev-parse" "--is-inside-work-tree") 0)
+ (let* ((branch (string-trim (shell-command-to-string "git rev-parse --abbrev-ref HEAD")))
+ (dirty (not (string= "" (string-trim (shell-command-to-string "git status --porcelain")))))
+ (branch-info (if (string= branch "HEAD") "" branch))
+ (dirty-info (if dirty " ✎" " ✔")))
+ (concat (propertize "⎇ " 'face 'modus-themes-fg-green-warmer)
+ (propertize branch-info 'face 'modus-themes-fg-magenta-warmer)
+ (propertize dirty-info 'face (if dirty 'modus-themes-fg-red 'modus-themes-fg-green))))))
+
+ (defun eshell-prompt-multiline ()
+ "Eshell Git prompt inspired by spaceship-prompt."
+ (let ((separator (propertize " | " 'face 'font-lock-comment-face))
+ (hr (propertize (concat "\n" (make-string (/ (window-total-width) 2) ?─) "\n") 'face 'font-lock-comment-face))
+ (dir (propertize (format "%s" (abbreviate-file-name (eshell/pwd))) 'face 'modus-themes-fg-yellow-warmer))
+ (git-info (eshell/git-info))
+ (time (propertize (format-time-string "%H:%M:%S") 'face 'font-lock-comment-face))
+ (sign (if (= (user-uid) 0)
+ (propertize "\n#" 'face 'modus-themes-fg-blue-intense)
+ (propertize "\nλ" 'face 'modus-themes-fg-red-warmer))))
+ ;; Build prompt
+ (concat hr dir separator git-info separator time sign " ")))
+
+ (setf eshell-prompt-function 'eshell-prompt-multiline
+ eshell-highlight-prompt nil)
:bind (("C-c e" . eshell)
:map eshell-mode-map
("C-l" . 'thanos/eshell-clear)