4

I have the following in my code to customize eshell:

(setq eshell-prompt-function (lambda nil
    (concat
     (propertize (eshell/pwd) 'face `(:foreground "blue"))
     (propertize " $ " 'face `(:foreground "green")))))
(setq eshell-highlight-prompt nil)

taken from here. For some reason through, my eshell goes to all white. This code used to work for me so I must have changed something else, but I can not see why my prompt is all white. Does this have anything to do with my ~/.bashrc or can somebody else suggest a reason why that would not color my prompt?

I am working with the GUI version on MS Windows and this all used to work.

1 Answer 1

6

Eshell is an independent command interpreter implemented in Elisp, so by default it should have nothing to do with your other dotfiles, such as ~/.bashrc.

The custom prompt function you list works for me in the development version of Emacs on GNU/Linux, so I assume the problem lies either between Emacs and Windows or with your user-init-file.

I am not qualified to debug or explain the former case, but the latter should be relatively straightforward to test. First invoke Emacs with the -Q option and then evaluate your listed code. See here and here for ways to interactively evaluate Lisp if this is not familiar to you. Whether the custom code is evaluated before or after invoking eshell should not make a difference in this case (in fact, you could even compare eshell's appearance before and after evaluating the code).

If the -Q option resolves your issue, this means it is probably arising from something in your user-init-file. In this case I recommend you recursively bisect it as per this answer and this answer by Drew. Otherwise I suggest emphasising that this support issue is Windows-specific.

P.S. I suggest an improvement to the custom code, to better align it with the default implementation of eshell:

(defun my-eshell-prompt ()
  "Highlight eshell pwd and prompt separately."
  (mapconcat
   (lambda (list)
     (propertize (car list)
                 'read-only      t
                 'font-lock-face (cdr list)
                 'front-sticky   '(font-lock-face read-only)
                 'rear-nonsticky '(font-lock-face read-only)))
   `((,(abbreviate-file-name (eshell/pwd)) :foreground "blue")
     (,(if (zerop (user-uid)) " # " " $ ") :foreground "green"))
   ""))

(setq eshell-highlight-prompt nil
      eshell-prompt-function  #'my-eshell-prompt)

Noteworthy changes:

  • Give eshell-prompt-function a human-readable name for M-x describe-variable (C-h v) to report.
  • Make all prompt components read-only, so that the prompt cannot be deleted as regular text. Allow text inserted before the prompt to inherit this property, as per eshell defaults.
  • Replace the face property with font-lock-face and do not allow text inserted after the prompt to inherit this property. I must admit I am not entirely familiar with the differences between face and font-lock-face, but I suggest this change because:
    • eshell does this;
    • it should achieve the same effect; and
    • the effects of font-lock-face can be toggled with font-lock-mode.
  • Choose between prompts # and $ depending on user privileges, as per Bourne and eshell defaults.
  • Try to abbreviate-file-name of current directory as per eshell defaults, e.g. display ~ instead of /path/to/user/home.
2
  • 1
    Great improvements
    – Startec
    Commented Jun 9, 2017 at 19:27
  • If the abbreviate-file-name does not work, it may be because the path to abbreviate is not a child of your home directory. In order to make it abbreviate other paths also, add the following command before all of the above: (setq directory-abbrev-alist (cons '("\`c:/This/Is/My/path" . "path") directory-abbrev-alist)) Also, see this: gnu.org/software/emacs/manual/html_node/elisp/…
    – Ioanna
    Commented Aug 28, 2018 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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