Zsh中的256色提示

Zsh中的256色提示

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

  local DEFAULT="\[\033[0;39m\]"
  local ROOK="\[\033[38;5;24m\]"
  PS1="${ROOK}\$${DEFAULT} "

答案1

export PS1='%F{214}%K{123}%m%k%f'

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.

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

$> print -P '%F{214}%K{123}%m%k%f'

答案2

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

export PS1='%{^[[01;38;05;214;48;05;123m%}%m%{^[[0m%} '

这将为您提供主机名以粗体显示的提示,前景色为 214,背景色为 123。

请注意,是^[通过键入Ctrl+vCtrl+来“输入”的[。请参阅这篇优秀文章“那个 256 色的东西" 获取完整的属性列表。

相关内容