configure zsh highlight for unknown command type

I have currently set up my ZSH highlighting like this:

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line)
typeset -A ZSH_HIGHLIGHT_STYLES # For main-highlighter
ZSH_HIGHLIGHT_STYLES[command]='fg=blue'
ZSH_HIGHLIGHT_STYLES[function]='fg=green'
ZSH_HIGHLIGHT_STYLES[builtin]='fg=red'
ZSH_HIGHLIGHT_STYLES[unknown]='fg=green,bold'
ZSH_HIGHLIGHT_STYLES[arg0]='fg=white'

I wanted to add a directive, so that a command word, which is not a valid command (i.e. not in the PATH, nor a function or alias; i.e. a word w, for which type w would print w not found) is shown in a different colour, so that I can already find typing errors while typing the comman line.

Example: If I want to type gawk, but start typing the command

gwk ...

instead (and gwk is not a valid command in my environment), I would like to see it a different colour, so that I am alerted of the typing mistake early.

I first thought that the style named arg0 would handle this, but obviously it does not.

Is this possible to achieve, and which highlight style would I have to use for this?


Solution 1:

You need to use unknown-token: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md


PS: I maintain a Zsh plugin called Z Colors that can convert your $LS_COLORS to zsh-syntax-highlighting. It takes care of that stuff automatically. 🙂