Last active
July 21, 2019 20:38
-
-
Save daviderestivo/94fa0cfa8b567571bac6c1cad11c100d to your computer and use it in GitHub Desktop.
Eshell prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun galactic-emacs-eshell-prompt () | |
"Customize eshell prompt. | |
This function requires `all-the-icons' package to be installed | |
(https://github.com/domtronn/all-the-icons.el)." | |
(if (display-graphic-p) | |
(setq galactic-emacs-header-bg "#282C34") | |
;; The background used when Emacs runs in a terminal | |
(setq galactic-emacs-header-bg "black")) | |
;; In order to set the eshell prompt correctly we need to | |
;; distinguish between the case where we are in a local folder or | |
;; the case where we are connected to a remote server via TRAMP | |
;; (i.e.). The shell need to be temporary restored to the | |
;; default one. | |
(let ((shell-file-name "/bin/sh")) | |
(progn | |
(if (file-remote-p default-directory) | |
(progn | |
(setq galactic-emacs-user-login-name (replace-regexp-in-string "\n$" "" | |
(shell-command-to-string "whoami")) | |
galactic-emacs-system-name (replace-regexp-in-string "\n$" "" | |
(shell-command-to-string "hostname")) | |
galactic-emacs-user-uid (string-to-number (replace-regexp-in-string "\n$" "" | |
(shell-command-to-string "id -u"))))) | |
(progn | |
(setq galactic-emacs-user-login-name (user-login-name) | |
;; Remove the domain name from the local eshell prompt | |
galactic-emacs-system-name (if (string-match-p (regexp-quote ".") system-name) | |
(car (split-string (system-name) "\\.")) | |
(system-name)) | |
galactic-emacs-user-uid (user-uid)))) | |
(concat | |
"┌─ " | |
(if (display-graphic-p) | |
(all-the-icons-faicon "folder-open-o") | |
"") | |
" " | |
(galactic-emacs-with-face (concat (eshell/pwd) " ") :background galactic-emacs-header-bg) | |
(if (string= (ignore-errors (vc-responsible-backend default-directory)) "Git") | |
(when (ignore-errors (vc-git--run-command-string default-directory "status" "-s")) | |
(progn | |
(setq git-status (split-string (vc-git--run-command-string default-directory "status" "-s"))) | |
(galactic-emacs-with-face | |
(format "[%s %s %s] " | |
(if (display-graphic-p) | |
(all-the-icons-faicon "git-square") | |
"Git") | |
(if (display-graphic-p) | |
(concat (all-the-icons-octicon "git-branch") ":" (car (vc-git-branches))) | |
(concat "branch" ":" (car (vc-git-branches)))) | |
(concat | |
"status:" | |
(if (member "A" git-status) "A" "-") ;; Added files (not committed) | |
(if (member "M" git-status) "M" "-") ;; Modified files | |
(if (member "D" git-status) "D" "-") ;; Deleted files | |
(if (member "??" git-status) "U" "-"))) ;; Untracked files | |
:background galactic-emacs-header-bg :foreground "LightGreen")))) | |
(galactic-emacs-with-face | |
(concat | |
"[" | |
(if (display-graphic-p) | |
(concat (all-the-icons-material "schedule") " ")) | |
(format-time-string "%Y-%m-%d %H:%M:%S" (current-time)) | |
"]") :background galactic-emacs-header-bg :foreground "gainsboro") | |
(galactic-emacs-with-face "\n└─> " :background galactic-emacs-header-bg) | |
(galactic-emacs-with-face galactic-emacs-user-login-name :foreground "LightBlue") | |
"@" | |
(galactic-emacs-with-face galactic-emacs-system-name :foreground "LightGreen") | |
(if (= galactic-emacs-user-uid 0) | |
(galactic-emacs-with-face " #" :foreground "LightRed") | |
" $") | |
" ")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The local eshell prompt looks like the following: