From 7e334e7fe8cf1fce3e4395a89111b4439019a296 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 20:14:45 +0000 Subject: [PATCH] Add ZSH_HIGHLIGHT_STYLES[file] style to change color for all files at once --- highlighters/main/README.md | 6 +++--- highlighters/main/main-highlighter.zsh | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 2aa9054..ed6ddca 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -70,8 +70,8 @@ By default files are colored in the same fashion as `ls` command, namely by comp # To disable higlighting for all files ZSH_HIGHLIGHT_STYLES[file]='none' - # To use $LS_COLORS use 'default', or just don't set ZSH_HIGHLIGHT_STYLES[file] at all - ZSH_HIGHLIGHT_STYLES[file]='default' + # To use LS_COLORS do not set this style at all + # ZSH_HIGHLIGHT_STYLES[file] It is also possible to change the color for one single file attribute/extenstion. To achieve this modify ZSH_HIGHLIGHT_FILES in ~/.zshrc: @@ -84,4 +84,4 @@ It is also possible to change the color for one single file attribute/extenstion # To set color for files with pdf extenstion ZSH_HIGHLIGHT_FILES[*.pdf]='fg=34' -Note that LS_COLORS uses ANSI color codes (not names as 'green') and so does ZSH_HIGHLIGHT_FILES by default, but ZSH_HIGHLIGHT_FILES[*.pdf]='fg=green' is possible too. However if you set color code by hand you must guarantee that your terminal is capable to display that color properly. In above examples 256 color palette is used. In case of doubt it is better to set ZSH_HIGHLIGHT_STYLES[file]='default' and change LS_COLORS via ~/.dircolors file. If ~/.dircolors files doesn't exist one can generae it by `dircolor` command. +Note that LS_COLORS uses ANSI color codes (not names as 'green') and so does ZSH_HIGHLIGHT_FILES by default, but ZSH_HIGHLIGHT_FILES[*.pdf]='fg=green' is possible too. However if you set color code by hand you must guarantee that your terminal is capable to display that color properly. In above examples 256 color palette is used. In case of doubt it is better not to set ZSH_HIGHLIGHT_STYLES[file] and change LS_COLORS via ~/.dircolors file. If ~/.dircolors files doesn't exist one can generate it by `dircolor` command. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4bab7f9..d897c67 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -44,6 +44,7 @@ : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} +: ${ZSH_HIGHLIGHT_STYLES[file]:=} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} @@ -310,6 +311,8 @@ _zsh_highlight_main_highlighter_check_file() [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1])) [[ -e $expanded_arg || -e $matched_file ]] && lsstyle=none || return 1 + [[ ! -z $ZSH_HIGHLIGHT_STYLES[file] ]] && lsstyle=$ZSH_HIGHLIGHT_STYLES[file] && return 0 + # [[ rs ]] # [[ -d $expanded_arg || -d $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[di] && return 0 [[ -h $expanded_arg || -h $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[ln] && return 0