Skip to content

Instantly share code, notes, and snippets.

@quantumman
Created September 23, 2011 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantumman/1236826 to your computer and use it in GitHub Desktop.
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..
(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