我试图在zsh完成脚本中找到一个_arguments
指令的示例,该脚本使用颜色打印某些参数。
https://wiki.archlinux.org/index.php/zsh#Colors
到目前为止,无论我尝试了什么,最终都会在屏幕上显示转义字符,而不是变成颜色。
答案 0 :(得分:0)
#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