256 colors in zsh-syntax-highlighting?

user3934727 picture user3934727 · Aug 13, 2014 · Viewed 8.8k times · Source

OK, so I'm using this little fancy cutting edge technology called zsh-syntax-highlighting and although I'm overall happy with the result I don't know how to set styles to anything but 8 basic colors (black, red, green, yellow, blue, magenta, cyan, white), e.g.

#works
ZSH_HIGHLIGHT_STYLES[path]='fg=red'
ZSH_HIGHLIGHT_STYLES[path]='fg=1'

#doesn't work
ZSH_HIGHLIGHT_STYLES[path]='fg=31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='31m'
ZSH_HIGHLIGHT_STYLES[path]='\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[1;38;5;118m%}'

So, how do I set more fancy colors for this zshzle plugin?

Answer

user3620917 picture user3620917 · Aug 19, 2014

As you pointed out in the comment to chepner answer terminator is a fork of gnome-terminal and it still uses a lot of functions from gnome. In fact it seems that the whole terminator VTE widget comes from gnome and gnome-terminal by defaults "supports" only 8 basic colors. You can check that with echotc Co command. It will return 8 for both of them and for xterm too (although in xterm case this is true and only 8 colors), so basically all 3 terminal emulators you tried so far.

Now, you noted that teminator (and gnome-terminal) can in fact display more colors, but this is only because it more or less processes all those special color codes without paying attention to TERM settings what does not obey standards but well, this is gnome. Anyway to make long story short you need to set TERM environment variable to something like xterm-256color and check again with echotc Co - you should now see 256, and your ZSH_HIGHLIGHT_STYLES[path]='fg=217' should work as well.

To always start with 256 colors you can put into you .zshrc

[[ "$TERM" == "xterm" ]] && export TERM=xterm-256color

and if you have any gnome shortcuts with terminator then change them as follows

terminator -e "TERM=xterm-256color pine"