Last active
March 9, 2018 19:30
-
-
Save alexjgriffith/84ee729939a6c4c112fb9843fa4dd17e to your computer and use it in GitHub Desktop.
View the current git branch in your elsip prompt.
This file contains 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 git-changes-p () | |
"Check if there are any changes to the git repo." | |
(with-temp-buffer | |
(process-file-shell-command "git status --porcelain" nil (current-buffer) nil) | |
(not(string= "" (buffer-string))))) | |
(defun git-branch () | |
"Return the current branch of the git repo." | |
(interactive) | |
(or (ignore-errors (magit-get-current-branch)) | |
(with-temp-buffer | |
(apply #'process-file "git" nil (list t nil) nil '("--no-pager" | |
"--literal-pathspecs" | |
"-c" | |
"core.preloadindex=true" | |
"symbolic-ref" | |
"HEAD" | |
"--short")) | |
(unless (bobp) | |
(goto-char (point-min)) | |
(buffer-substring-no-properties (point) (line-end-position)))))) | |
(defun two-line-eshell-prompt () | |
"A simple two line eshell prompt." | |
(concat | |
(propertize (concat (eshell/pwd) " ") | |
'face '(font-lock-function-name-face | |
:weight bold)) | |
(propertize | |
(or (ignore-errors (format "(%s:%s)" | |
(vc-responsible-backend default-directory) | |
(git-branch))) "") | |
'face | |
(if (git-changes-p) | |
'font-lock-warning-face | |
'font-lock-function-name-face)) | |
(propertize "\n~> " | |
'face' (font-lock-function-name-face | |
:weight bold)) | |
(propertize user-login-name | |
'face '(:foreground "green")) | |
"@" | |
(propertize "localhost" | |
'face '(:foreground "green")) | |
(if (= (user-uid) 0) | |
(propertize " #" | |
'face '(:foreground "red")) | |
" $") | |
" ")) | |
(defun eshell-hook-function() | |
"Define bindings for eshell mode." | |
;; makes eshell behave more like shell | |
;; use M-p M-n rather than up and down | |
(define-key eshell-mode-map (kbd "<up>") 'nil) | |
(define-key eshell-mode-map (kbd "<down>") 'nil)) | |
(setq eshell-prompt-function 'two-line-eshell-prompt) | |
(setq eshell-highlight-prompt nil) | |
(add-hook 'eshell-mode-hook 'eshell-hook-function) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment