Made Eshell banner more reliable

This commit is contained in:
Howard Abrams 2024-04-25 13:39:51 -07:00
parent 34b2ed6305
commit ff0ef354f7

View file

@ -1429,36 +1429,32 @@ Whenever I open a shell, I instinctively type =ls= … so why not do that automa
(bg (face-attribute 'default :foreground)) (bg (face-attribute 'default :foreground))
(bg "#c09644") (bg "#c09644")
(dd (thread-last default-directory (dd (thread-last default-directory
(replace-regexp-in-string (getenv "HOME") "~"))) (replace-regexp-in-string (getenv "HOME") "~")))
(gs (or (ha-eshell-banner-git-branch) ""))) (gs (or (ha-eshell-banner-git-branch) "")))
(ignore-errors (condition-case err
(concat (concat
;; Line 1 ;; Line 1
(propertize (propertize
(format " %s • ⑆ %s " dd gs) (format " %s • ⑆ %s " dd gs)
'face `(:background ,bg :foreground ,fg)) 'face `(:background ,bg :foreground ,fg))
"\n" "\n"
;; Line 2 ;; Line 2
(ha-dad-joke) (ha-dad-joke)
"\n\n")))) "\n\n")
(error "🐚 Welcome to Eshell\n\n"))))
(defun ha-eshell-banner-git-branch (&optional directory) (defun ha-eshell-banner-git-branch ()
"Returns the simplified Git branch for DIRECTORY." "Return simplified Git branch for current directory."
(let (default-directory) (thread-last "git status --short --branch --ahead-behind 2>/dev/null"
(when directory (shell-command-to-list)
(setq default-directory directory)) (first)
(ignore-errors (replace-regexp-in-string
(thread-last "git status --short --branch --ahead-behind 2>/dev/null" (rx "## "
(shell-command-to-list) (group (zero-or-more not-newline))
(first) (zero-or-more anychar))
(replace-regexp-in-string "\\1")
(rx "## " (replace-regexp-in-string
(group (zero-or-more not-newline)) (rx "...") " → ")))
(zero-or-more anychar))
"\\1")
(replace-regexp-in-string
(rx "...") " → "))))
)
#+end_src #+end_src
* Shell Windows * Shell Windows
Now that I often need to pop into remote systems to run a shell or commands, I create helper functions to create those buffer windows. Each buffer begins with =eshell=: allowing me to have more than one eshells, typically, one per project. Now that I often need to pop into remote systems to run a shell or commands, I create helper functions to create those buffer windows. Each buffer begins with =eshell=: allowing me to have more than one eshells, typically, one per project.