zoppo / zoppo

The crippled configuration framework for Zsh
34 stars 3 forks source link

Extending syntax-highlighter #6

Open rchady opened 9 years ago

rchady commented 9 years ago

I'm still learning my way around here so I apologize up front if these end up being silly questions.

I was looking at the syntax-highlighter plugin and found that you can't use zstyle to set ZSH_HIGHTLIGHT_STYLES. I tried to extend that using zdefault, but doing so clobbers the defaults that get set by the actual syntax highlighters.

Question: Is there a way to only override the values for ZSH_HIGHLIGHT_STYLES that are in :zoppo:plugin:syntax-highlight:styles', but otherwise leave the other values of ZSH_HIGHLIGHT_STYLES alone? If nothing else I suppose I could loop through the contents and only set those... but thought perhaps you had a way to do that using zdefault already that I was missing.

meh commented 9 years ago

The customization of syntax-highlighter definitely needs a revamp.

Please do keep opening issues you find, so I can keep track of what to rework or fix up.

rchady commented 9 years ago

Well, on the surface extending it appears to be trivial.. something like

zdefault -a ':zoppo:plugin:syntax-highlight' styles ZSH_HIGHLIGHT_STYLES 'alias' 'fg=white,bold'

That does indeed work actually. The problem is that actual syntax highlighter sets its own default styles and by using the above those default values all get clobbered. If you do something like ${(@kv)ZSH_HIGHLIGHT_STYLES} it will give you the default like you want, but the moment you actually it to something else you lose the rest of the defaults.

The best avenue I can see is to walk through :zoppo:plugin:syntax-highlight:styles and set ZSH_HIGHLIGHT_STYLE[$style].

rchady commented 9 years ago

This is what I came up with:

typeset -A highlight_styles
zdefault -a ':zoppo:plugin:syntax-highlight' styles highlight_styles ${(@kv)ZSH_HIGHLIGHT_STYLES}

for style (${(@k)highlight_styles}); do
  ZSH_HIGHLIGHT_STYLES[$style]="$highlight_styles[$style]"
done