How can I change the color of my prompt in zsh (different from normal text)?

前端 未结 10 1917
醉梦人生
醉梦人生 2020-12-07 07:34

To recognize better the start and the end of output on a commandline, I want to change the color of my prompt, so that it is visibly different from the programs output. As I

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 08:13

    To complement all of the above answers another convenient trick is to place the coloured prompt settings into a zsh function. There you may define local variables to alias longer commands, e.g. rc=$reset_color or define your own colour variables. Don't forget to place it into your .zshrc file and call the function you have defined:

    # Coloured prompt
    autoload -U colors && colors
    function myprompt {
      local rc=$reset_color
      export PS1="%F{cyan}%n%{$rc%}@%F{green}%m%{$rc%}:%F{magenta}%~%{$rc%}%# "
    }
    myprompt
    

提交回复
热议问题