Frage

I am trying to set the list-colors for a completion function, but I just can't wrap my head around the styling syntax.

zstyle ':completion:*:tasks:*' list-colors "=(#b) #([^ ]#)*=$color[white]=$color[yellow]=$color[red]"

All i know is that '#' and '##' are the regex equivalents of '.' and '+'. Every time I try to modify the syntax just a little, the matching seems to break. Could somebody please post some easy examples or resources (unfortunately the zsh docs have very few examples)? How would I, for instance match the string '--'?

War es hilfreich?

Lösung

Here come a few examples.

Something simple for beginning, let all parameters tag be in green:

zstyle ':completion:*:parameters'  list-colors '=*=32'

As you can see syntax is '=pattern=format'. Since * matches everything and 32 is ANSI green code, thus all parameters will be green.

Now lets show all commands in bolded red

zstyle ':completion:*:commands' list-colors '=*=1;31'

but built-in commands with a little bit more sophisticated color (from 256 palette)

zstyle ':completion:*:builtins' list-colors '=*=1;38;5;142'

analogously for aliases

zstyle ':completion:*:aliases' list-colors '=*=2;38;5;128'

Now lets go to patterns, and colorize different parts of completion differently, say we want a kill processes in 3 different colors:

zstyle ':completion:*:*:kill:*' list-colors '=(#b) #([0-9]#)*( *[a-z])*=34=31=33'

Here syntax is a little bit more complicated, namely '=(#b)(pattern1)(pattern2)=format0=format1=format2' where format0 is used for everything which do not match any patterns. So processes IDs (first pattern) will be in red, processes names (second pattern) in yellow, and the rest in blue:

enter image description here

Lastly lets try something useful with '--' string which you asked for:

zstyle ':completion:*:options' list-colors '=^(-- *)=34'

This will present all command options in blue, but description of that options will stay normal.

enter image description here

Notice that some options starts with '--', so we have to use '-- ' (with space) to match only descriptions, and negate pattern with ^ to apply color for options.

Hope this help

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top