简体   繁体   English

MacOS zsh 提示不显示紫色?

[英]MacOS zsh prompt does not show Purple?

I'm trying to make my git branch purple.我正在尝试将我的git branch紫色。 Here's what I have:这是我所拥有的:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    # git symbolic-ref --short HEAD 2> /dev/null
}

setopt PROMPT_SUBST
PS1='%{%F{green}%}%n@%m:%{%F{yellow}%}%1~%{%F{red}%}$(parse_git_branch)%{%F{none}%}$ '

So my username@machine: is green and foldername is yellow as expected.所以我的username@machine:是绿色的, foldername是黄色的。 However, if I change the colour red to purple or anything else but white or cyan , my prompt doesn't show the correct colour.但是,如果我将red更改为purplewhitecyan以外的任何其他颜色,我的提示不会显示正确的颜色。

FYI: Here's what I have in bash :仅供参考:这是我在bash中的内容:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[0;32m\]\u@\h\[\033[00m\]:\[\033[0;33m\]\W\[\033[0;35m\]\$(parse_git_branch)\[\033[00m\]\$ "

I've tried:我试过了:

  • for i in {1..256}; do print -P "%F{$i}Color: $i"; done; and my terminal shows all ranges of colours so I replaced red with some ANSI code but the branch turns cyan .我的终端显示所有颜色范围,所以我用一些 ANSI 代码替换了red ,但分支变成了cyan
  • \e[0;31m$ \e[0m with ANSI escape char but it still doesn't work. \e[0;31m$ \e[0m带有 ANSI 转义字符,但它仍然不起作用。
  • $F{} , $fg{} , etc. $F{}$fg{}等。
  • And of course quit the terminal, source the ~/.zshrc file, restart computer.当然退出终端,获取~/.zshrc文件,重新启动计算机。

What am I missing?我错过了什么?

With %F{...} , you can use one of the following:使用%F{...} ,您可以使用以下方法之一:

  1. An integer corresponding to an entry in your terminal's palette (the range depends on the size of that palette). integer 对应于终端调色板中的条目(范围取决于该调色板的大小)。 That's what you saw with your for loop (though you can use i=0 as well; see the next point).这就是您在for循环中看到的(尽管您也可以使用i=0 ;请参阅下一点)。 Eg %F{red}例如%F{red}

  2. One of the predefined names black , red , green , yellow , blue , magenta , cyan , or white (corresponding to palette entries 0 through 7, respectively).预定义名称之一blackredgreenyellowbluemagentacyanwhite (分别对应于调色板条目 0 到 7)。 Eg %F{1} (Note that some terminals may support additional names.)例如%F{1} (请注意,某些终端可能支持其他名称。)

  3. An RGB value, starting with a # and followed by 3 or 6 hexadecimal digits.一个 RGB 值,以#开头,后跟 3 或 6 个十六进制数字。 Eg %F{#f00} or %F{#ff0000}`例如%F{#f00}或 %F{#ff0000}`

    Assuming your terminal allows it, this provides you with more control over the color displayed, as both %F{red} and %F{1} simply tell the terminal to display color #1 (which the terminal emulator may allow to be set to any color the user likes).假设您的终端允许它,这为您提供了对显示颜色的更多控制,因为%F{red}%F{1}都只是告诉终端显示颜色 #1(终端仿真器可能允许将其设置为用户喜欢的任何颜色)。 %F{#ff0000} , on the other hand, will always display the brightest shade of red available.另一方面, %F{#ff0000}始终显示可用的最亮的红色阴影。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM