Colors in Emacs shell prompt

后端 未结 4 2047
故里飘歌
故里飘歌 2021-01-17 14:39

Is it possible to use colors in the Emacs shell prompt (the prompt itself, not the rest of the shell screen) with the bash PS1 variable? I believe I have the syntax correct

相关标签:
4条回答
  • 2021-01-17 15:19

    Figured it out: The comint-highlight-prompt face was set to inherit from minibuffer-prompt, which was setting the :weight, :foreground and :background. Removing the inheritance prevented the colors set in PS1 from being overridden by the comint-highlight-prompt face. Added this to my .emacs file.

    (set-face-attribute 'comint-highlight-prompt nil
                        :inherit nil)
    

    Also, M-x customize-group <ret> font-lock-faces was helpful in figuring this out.

    0 讨论(0)
  • 2021-01-17 15:20

    I would recommend not to change the face globally (since there are many comint users besides shell mode) but in a buffer specific manner by setting a mode hook:

    (add-hook 'shell-mode-hook
          (lambda ()
            (face-remap-set-base 'comint-highlight-prompt :inherit nil)))
    
    0 讨论(0)
  • 2021-01-17 15:23

    You'll need to use ansi-term rather than shell for terminal colours.

    0 讨论(0)
  • 2021-01-17 15:28

    I use that to change the terminal color and the information in mac, maybe can help:

    Cyan="$(tput setaf 6)"
    NC="$(tput sgr0)" # No Color
    export PS1="$Cyan.Where-> \w\n\\$\[$NC\]"
    
    0 讨论(0)
提交回复
热议问题