Zsh 中的 256 色提示

Sar*_*use 15 colors zsh

如何将我的提示设置为 256 色?我正在寻找与 bash 提示符等效的命令:

  local DEFAULT="\[\033[0;39m\]"
  local ROOK="\[\033[38;5;24m\]"
  PS1="${ROOK}\$${DEFAULT} "
Run Code Online (Sandbox Code Playgroud)

ДМИ*_*КОВ 16

export PS1='%F{214}%K{123}%m%k%f'
Run Code Online (Sandbox Code Playgroud)

来自man zshmisc

   %F (%f)
          Start (stop) using a different foreground colour, if supported by the terminal.  The colour may be specified two ways: either as a numeric argument, as normal, or by a sequence in braces following the %F, for example %F{red}.  In the latter case the values allowed are as described for the fg zle_highlight attribute; see  Char?
          acter Highlighting in zshzle(1).  This means that numeric colours are allowed in the second format also.

   %K (%k)
          Start (stop) using a different bacKground colour.  The syntax is identical to that for %F and %f.
Run Code Online (Sandbox Code Playgroud)

也可以尝试一下,它可以这样使用:

$> print -P '%F{214}%K{123}%m%k%f'
Run Code Online (Sandbox Code Playgroud)


phu*_*ehe 11

首先,确保您的终端支持 256 种颜色,我想您已经拥有了。其次,使用PS1具有正确代码的变量,例如:

export PS1='%{^[[01;38;05;214;48;05;123m%}%m%{^[[0m%} '
Run Code Online (Sandbox Code Playgroud)

这会给你一个提示,主机名以粗体显示,前景色为 214,背景色为 123。

请注意,^[通过键入Ctrl+vCtrl+来“输入” [。请参阅这篇出色的文章“那 256 色的东西”,了解完整的属性列表。