From ff0ef354f79c9e3550d0cc5bcd3aa26f824acc3f Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 25 Apr 2024 13:39:51 -0700 Subject: [PATCH] Made Eshell banner more reliable --- ha-eshell.org | 52 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/ha-eshell.org b/ha-eshell.org index fb55c01..d7605bf 100644 --- a/ha-eshell.org +++ b/ha-eshell.org @@ -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.