Basically I try to enable showing git branch I'm in in eshell buffer. The elisp I got works fine. But I will constantly run into "Text is read only " and have to kill the eshell buffer to start over.

;; eshell promopt
(defun my-current-git-branch ()
  (let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
                           when (string-match "^\*" match)
                           collect match))))
    (if (not (eq branch nil))
        (concat ":" (substring branch 2))

(defun my-eshell-prompt ()
  (concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
          (propertize (my-current-git-branch) 'face 'font-lock-function-name-face)
          (propertize " λ " 'face 'font-lock-constant-face)))

;; em-prompt
(setq eshell-prompt-function 'my-eshell-prompt)

I am using Arch Linux and Emacs25. Does anyone have any idea to solve or a better approach?

  • Did you update eshell-prompt-regexp? – npostavs Sep 9 '16 at 21:02
  • Oops, that is the part I missed. How can I know the exact eshell-prompt-regexp value I want? Thx – shwsun Sep 9 '16 at 22:46
  • I figured out it should be (setq eshell-prompt-regexp "^[^#$]*:$# "). Do you want to put out answer or you just want me to quote it? Thx very much – shwsun Sep 9 '16 at 22:58
  • Go ahead and make an answer of it, if it works. I would think it should be something like (setq eshell-prompt-regexp "^[^λ]+ λ ") though. – npostavs Sep 10 '16 at 3:13

Thanks to @npostavs, the thing that I missed previously is you have to update eshell-prompt-regexp as you modified the eshell prompt. This is also vaguely mentioned in EmacsWiki: https://www.emacswiki.org/emacs/EshellPrompt

In my case, you can add sth like (setq eshell-prompt-regexp "^[^λ]+ λ ").

  • 2
    It's mentioned in the docstring of eshell-prompt-function. – npostavs Sep 11 '16 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.