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 "#c09644")
(dd (thread-last default-directory
(replace-regexp-in-string (getenv "HOME") "~")))
(replace-regexp-in-string (getenv "HOME") "~")))
(gs (or (ha-eshell-banner-git-branch) "")))
(ignore-errors
(concat
;; Line 1
(propertize
(format " %s • ⑆ %s " dd gs)
'face `(:background ,bg :foreground ,fg))
"\n"
;; Line 2
(ha-dad-joke)
"\n\n"))))
(condition-case err
(concat
;; Line 1
(propertize
(format " %s • ⑆ %s " dd gs)
'face `(:background ,bg :foreground ,fg))
"\n"
;; Line 2
(ha-dad-joke)
"\n\n")
(error "🐚 Welcome to Eshell\n\n"))))
(defun ha-eshell-banner-git-branch (&optional directory)
"Returns the simplified Git branch for DIRECTORY."
(let (default-directory)
(when directory
(setq default-directory directory))
(ignore-errors
(thread-last "git status --short --branch --ahead-behind 2>/dev/null"
(shell-command-to-list)
(first)
(replace-regexp-in-string
(rx "## "
(group (zero-or-more not-newline))
(zero-or-more anychar))
"\\1")
(replace-regexp-in-string
(rx "...") " → "))))
)
(defun ha-eshell-banner-git-branch ()
"Return simplified Git branch for current directory."
(thread-last "git status --short --branch --ahead-behind 2>/dev/null"
(shell-command-to-list)
(first)
(replace-regexp-in-string
(rx "## "
(group (zero-or-more not-newline))
(zero-or-more anychar))
"\\1")
(replace-regexp-in-string
(rx "...") " → ")))
#+end_src
* 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.