サイトマップ 更新履歴 ニュース Elispセクション 利用手引

EshellPrompt

Introduction

The [[Eshell?]] prompt is generated by the function stored in ‘eshell-prompt-function’. When moving through the buffer, eshell also needs to know which lines start with a prompt. Therefore, whatever ‘eshell-prompt-function’ prints must be matched by ‘eshell-prompt-regexp’.

Here is a simple example:

(setq eshell-prompt-function
  (lambda ()
    (concat (format-time-string "%Y-%m-%d %H:%M" (current-time))
      (if (= (user-uid) 0) " # " " $ "))))

The resulting prompt:

2006-01-10 11:03 $ 
 (setq eshell-prompt-function
  (lambda nil
    (concat
     (eshell/pwd)
     " $ ")))

The resulting prompt:

 c:/home $ 

A colored prompt

If you want colors in your prompt, use something like this:

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

A fancy prompt

Example of a more fancy eshell prompt with different colors, time, pwd, version control info and horizontal line after each command.

  (defmacro with-face (str &rest properties)
    `(propertize ,str 'face (list ,@properties)))
  
  (defun shk-eshell-prompt ()
    (let ((header-bg "#fff"))
      (concat
       (with-face (concat (eshell/pwd) " ") :background header-bg)
       (with-face (format-time-string "(%Y-%m-%d %H:%M) " (current-time)) :background header-bg :foreground "#888")
       (with-face
        (or (ignore-errors (format "(%s)" (vc-responsible-backend default-directory))) "")
        :background header-bg)
       (with-face "\n" :background header-bg)
       (with-face user-login-name :foreground "blue")
       "@"
       (with-face "localhost" :foreground "green")
       (if (= (user-uid) 0)
           (with-face " #" :foreground "red")
         " $")
       " ")))
  (setq eshell-prompt-function 'shk-eshell-prompt)
  (setq eshell-highlight-prompt nil)

CategoryEshell