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

前端 未结 10 1892
醉梦人生
醉梦人生 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条回答
  •  旧巷少年郎
    2020-12-07 08:06

    Put this in ~/.zshrc:

    autoload -U colors && colors
    PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
    

    Supported Colors:
    red, blue, green, cyan, yellow, magenta, black, & white (from this answer) although different computers may have different valid options.

    Surround color codes (and any other non-printable chars) with %{....%}. This is for the text wrapping to work correctly.

    Additionally, here is how you can get this to work with the directory-trimming from here.

    PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%(5~|%-1~/.../%3~|%4~) %{$reset_color%}%% "
    

提交回复
热议问题