zsh完成_arguments中的颜色

时间:2017-10-24 06:55:08

标签: zsh

我试图在zsh完成脚本中找到一个_arguments指令的示例,该脚本使用颜色打印某些参数。

https://wiki.archlinux.org/index.php/zsh#Colors

到目前为止,无论我尝试了什么,最终都会在屏幕上显示转义字符,而不是变成颜色。

1 个答案:

答案 0 :(得分:0)

abt很晚但仍然, 我发现以下代码将突出显示完成结果的颜色。 对动态生成的完成很有用。

#compdef colorgrep
local -a colors
    colors="$( _call_program 'colgrep' grep --help 2>/dev/null |\
      awk -vtick="'" -F' ' "BEGIN { OFS=\"\"; red=\"\033[31m\" ;white=\"\033[37m\"; };
      /^\s+-/ {
          gsub(/[:\`\]\[]|tick|the\s/,\"\",\$0);
          gsub(/\s\s/,\"\",\$0);
          split(\$1,option,/[=,]/);
          gsub(\$1,\"\",\$0);
          gsub(\$2,\"\",\$0);
          \$0=red\$0white;
          printf \"%s[%s]:%s:\n\",option[1],\$0,option[2] }" )"
      #convert to array
      colors=("${(f)colors}")
_arguments $colors