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

@ -1431,7 +1431,7 @@ Whenever I open a shell, I instinctively type =ls= … so why not do that automa
(dd (thread-last default-directory
(replace-regexp-in-string (getenv "HOME") "~")))
(gs (or (ha-eshell-banner-git-branch) "")))
(ignore-errors
(condition-case err
(concat
;; Line 1
(propertize
@ -1440,14 +1440,11 @@ Whenever I open a shell, I instinctively type =ls= … so why not do that automa
"\n"
;; Line 2
(ha-dad-joke)
"\n\n"))))
"\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
(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)
@ -1457,8 +1454,7 @@ Whenever I open a shell, I instinctively type =ls= … so why not do that automa
(zero-or-more anychar))
"\\1")
(replace-regexp-in-string
(rx "...") " → "))))
)
(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.