zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
20k stars 1.33k forks source link

Document how to reduce colorfulness #234

Open danielshahaf opened 8 years ago

danielshahaf commented 8 years ago

Some people find the default colorscheme too colorful (e.g., [1]).

danielshahaf commented 8 years ago

One option: support "themes" which are specifications of colors for multiple styles. In main-highlighter.zsh, replace the setting of default styles with

. themes${$ZSH_HIGHLIGHTER_THEME:-default}.zsh

to let people set multiple colors in one shot.

(Idea by @phy1729)

johnnybarrels commented 4 years ago

"support "themes...to let people set multiple colors in one shot."

I couldn't agree more with this! Would love it if this support existed

danielshahaf commented 4 years ago

It does, on the themes branch. Or you can set ZSH_HIGHLIGHT_STYLES by hand.

nhooyr commented 4 years ago

Is it possible to clear the default styles?

danielshahaf commented 4 years ago

This should do it:

source /path/to/zsh-syntax-highlighting.zsh
() {
    local -a new_values; new_values=(none)
    ZSH_HIGHLIGHT_STYLES=( ${${(@k)ZSH_HIGHLIGHT_STYLES[(I)*]}:^^new_values} )
}
nhooyr commented 4 years ago

Not sure how that works but I ended up doing this:

source_if_exists /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
typeset -A ZSH_HIGHLIGHT_STYLES # In case it doesn't exist above.
ZSH_HIGHLIGHT_STYLES=()

# Now my custom theme.
ZSH_HIGHLIGHT_STYLES[reserved-word]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[precommand]="fg=red"
ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[rc-quote]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=black"
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[redirection]="fg=magenta"
ZSH_HIGHLIGHT_STYLES[comment]="fg=244"

Seems to work great!

danielshahaf commented 4 years ago

Thanks for sharing your solution!

danielshahaf commented 4 years ago

As to how what I posted works: it uses several parameter expansion flags which, in combination, have the effect of setting ZSH_HIGHLIGHT_STYLES[$k]=none for every $k which is an already-existing key of ZSH_HIGHLIGHT_STYLES. Sorry, I don't have time to post a step-by-step explanation, but the flags are documented in zshall(1) in the sections "Parameter Expansion Flags" and "Subscript Flags".

nhooyr commented 4 years ago

As to how what I posted works: it uses several parameter expansion flags which, in combination, have the effect of setting ZSH_HIGHLIGHT_STYLES[$k]=none for every $k which is an already-existing key of ZSH_HIGHLIGHT_STYLES. Sorry, I don't have time to post a step-by-step explanation, but the flags are documented in zshall(1) in the sections "Parameter Expansion Flags" and "Subscript Flags".

Makes sense. Thanks for the description.