Created
September 23, 2011 05:43
-
-
Save quantumman/1236826 to your computer and use it in GitHub Desktop.
eshell prompt with git current branch name. but it does not work well..
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
(require 'vc-git) | |
(defun get-git-branch-name (path) | |
(let ((git-directory (concat path "/.git"))) | |
(if (file-exists-p git-directory) | |
(concat " (" (vc-git-mode-line-string git-directory) ") ") | |
"" | |
))) | |
(defun custom:eshell-prompt-function () | |
(let ((hostname (eshell:string-shorten (system-name) 5)) | |
(absolute-current-path (eshell/pwd)) | |
(git-branch-name (get-git-branch-name (eshell/pwd)))) | |
(concat (getenv "USER") | |
"@" hostname | |
":" (eshell:relative-file-path) | |
git-branch-name | |
"$ "))) | |
(setq eshell-prompt-function #'custom:eshell-prompt-function) | |
;;; above code shows a branch name correctly in the first time. | |
;;; however, in switching branches, then it does not work well. | |
;;; the prompt just still shows the branch name in the first time. | |
;;; ex.) ~/ $ cd working | |
;;; ~/working (master) $ git checkout topic | |
;;; ~/working (master) $ ## "topic" should appear in the prompt... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment