From 1a8e14fad2df3ea25341fb1dec88d13fe4f82200 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Tue, 23 Sep 2014 22:38:27 +0000 Subject: [PATCH 01/24] Add command_prefix style --- highlighters/main/main-highlighter.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 72b48f0..1b758be 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -37,6 +37,7 @@ : ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[command_prefix]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} @@ -126,6 +127,8 @@ _zsh_highlight_main_highlighter() *) if _zsh_highlight_main_highlighter_check_assign; then style=$ZSH_HIGHLIGHT_STYLES[assign] new_expression=true + elif _zsh_highlight_main_highlighter_check_command; then + style=$ZSH_HIGHLIGHT_STYLES[command_prefix] elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] = $histchars[0,1] ]]; then @@ -238,3 +241,12 @@ _zsh_highlight_main_highlighter_highlight_string() region_highlight+=("$j $k $style") done } + +## Check if command with given prefix exists +_zsh_highlight_main_highlighter_check_command() +{ + setopt localoptions nonomatch + local -a prefixed_command + for p in $path; do prefixed_command+=( $p/${arg}*(N) ); done + [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos && $#prefixed_command > 0 ]] && return 0 || return 1 +} From 85d1268b5a7c6534213fbcce876ff2c7ebe4cba7 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Tue, 23 Sep 2014 22:51:49 +0000 Subject: [PATCH 02/24] Changed ${#BUFFER} to ${#LBUFFER} in function _zsh_highlight_main_highlighter_check_path() in order to allow edit in the middle of the line without losing path colors in some cases --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1b758be..e6d9b88 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -191,7 +191,7 @@ _zsh_highlight_main_highlighter_check_path() [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 done [[ ! -e ${expanded_path:h} ]] && return 1 - if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]]; then + if [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]]; then local -a tmp # got a path prefix? tmp=( ${expanded_path}*(N) ) From 28a5c6e3f0d652cf59df75b90ac1498d495f0904 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Tue, 23 Sep 2014 23:44:45 +0000 Subject: [PATCH 03/24] Add highlighting for files based on $LS_COLORS environment variable. --- highlighters/main/main-highlighter.zsh | 93 +++++++++++++++++++++++++- zsh-syntax-highlighting.zsh | 1 + 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e6d9b88..09cc78b 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -66,7 +66,7 @@ _zsh_highlight_main_highlighter() { emulate -L zsh setopt localoptions extendedglob bareglobqual - local start_pos=0 end_pos highlight_glob=true new_expression=true arg style sudo=false sudo_arg=false + local start_pos=0 end_pos highlight_glob=true new_expression=true arg style lsstyle sudo=false sudo_arg=false typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS @@ -84,7 +84,7 @@ _zsh_highlight_main_highlighter() ) for arg in ${(z)BUFFER}; do - local substr_color=0 + local substr_color=0 isfile=false local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}})) @@ -136,6 +136,7 @@ _zsh_highlight_main_highlighter() else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi + _zsh_highlight_main_highlighter_check_file && isfile=true ;; esac fi @@ -160,14 +161,21 @@ _zsh_highlight_main_highlighter() else style=$ZSH_HIGHLIGHT_STYLES[default] fi + _zsh_highlight_main_highlighter_check_file && isfile=true ;; esac fi # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] + if [[ $isfile == true ]]; then + start_file_pos=$((start_pos+${#arg}-${#arg:t})) + end_file_pos=$end_pos + end_pos=$((end_pos-${#arg:t})) + region_highlight+=("$start_file_pos $end_file_pos $lsstyle") + fi [[ $substr_color = 0 ]] && region_highlight+=("$start_pos $end_pos $style") [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true - start_pos=$end_pos + [[ $isfile == true ]] && start_pos=$end_file_pos || start_pos=$end_pos done } @@ -250,3 +258,82 @@ _zsh_highlight_main_highlighter_check_command() for p in $path; do prefixed_command+=( $p/${arg}*(N) ); done [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos && $#prefixed_command > 0 ]] && return 0 || return 1 } + +## Fill table with colors and file types from $LS_COLORS +_zsh_highlight_files_highlighter_fill_table_of_types() +{ + local group type code ncolors=$(echotc Co) + local -a attrib + + for group in ${(s.:.)LS_COLORS}; do + type=${group%=*} + code=${group#*=} + attrib=() + takeattrib ${(s.;.)code} + ZSH_HIGHLIGHT_FILES+=($type ${(j.,.)attrib}) + done +} + +## Take attributes from unfolded $LS_COLORS code +takeattrib() +{ + while [ "$#" -gt 0 ]; do + [[ $1 == 38 && $2 == 5 ]] && {attrib+=("fg=$3"); shift 3; continue} + [[ $1 == 48 && $2 == 5 ]] && {attrib+=("bg=$3"); shift 3; continue} + case $1 in + 00|0) attrib+=("none"); shift;; + 01|1) attrib+=("bold" ); shift;; + 02|2) attrib+=("faint"); shift;; + 03|3) attrib+=("italic"); shift;; + 04|4) attrib+=("underscore"); shift;; + 05|5) attrib+=("blink"); shift;; + 07|7) attrib+=("standout"); shift;; + 08|8) attrib+=("concealed"); shift;; + 3[0-7]) attrib+=("fg=$(($1-30))"); shift;; + 4[0-7]) attrib+=("bg=$(($1-40))"); shift;; + 9[0-7]) [[ $ncolors == 256 ]] && attrib+=("fg=$(($1-82))") || attrib+=("fg=$(($1-90))" "bold"); shift;; + 10[0-7]) [[ $ncolors == 256 ]] && attrib+=("bg=$(($1-92))") || attrib+=("bg=$(($1-100))" "bold"); shift;; + *) shift;; + esac + done +} + +## Check if the argument is a file, if yes change the style accordingly +_zsh_highlight_main_highlighter_check_file() +{ + setopt localoptions nonomatch + local expanded_arg matched_file + + expanded_arg=${(Q)~arg} + [[ -z $expanded_arg ]] && return 1 + [[ -d $expanded_arg ]] && return 1 + [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1])) + [[ -e $expanded_arg || -e $matched_file ]] && lsstyle=none || return 1 + + # [[ 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 + # [[ mh ]] + [[ -p $expanded_arg || -p $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[pi] && return 0 + [[ -S $expanded_arg || -S $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[so] && return 0 + # [[ do ]] + [[ -b $expanded_arg || -b $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[bd] && return 0 + [[ -c $expanded_arg || -c $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[cd] && return 0 + # [[ or ]] + # [[ mi ]] + [[ -u $expanded_arg || -u $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[su] && return 0 + [[ -g $expanded_arg || -g $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[sg] && return 0 + # [[ ca ]] + # [[ tw ]] + # [[ ow ]] + [[ -k $expanded_arg || -k $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[st] && return 0 + [[ -x $expanded_arg || -x $matched_file ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[ex] && return 0 + + [[ -e $expanded_arg ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[*.$expanded_arg:e] && return 0 + [[ -n $matched_file:e ]] && lsstyle=$ZSH_HIGHLIGHT_FILES[*.$matched_file:e] && return 0 + + return 0 +} + +## Fill table only once, at the initialization process +_zsh_highlight_files_highlighter_fill_table_of_types diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index cdbe4c4..bb9facb 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -35,6 +35,7 @@ # Array declaring active highlighters names. typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS +typeset -gA ZSH_HIGHLIGHT_FILES # Update ZLE buffer syntax highlighting. # From f342c5e0cdaf3a0696ffc03fee2310467386669a Mon Sep 17 00:00:00 2001 From: jimmijj Date: Wed, 24 Sep 2014 00:04:49 +0000 Subject: [PATCH 04/24] Added missing separators: '&|', '|&' and '&!' --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 09cc78b..751fe58 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -73,7 +73,7 @@ _zsh_highlight_main_highlighter() region_highlight=() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( - '|' '||' ';' '&' '&&' + '|' '||' ';' '&' '&&' '&|' '|&' '&!' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( 'builtin' 'command' 'exec' 'nocorrect' 'noglob' From 4a3b2cd89f3cec4cf3adddb9b2c4b6243bb711dd Mon Sep 17 00:00:00 2001 From: jimmijj Date: Wed, 24 Sep 2014 01:51:14 +0000 Subject: [PATCH 05/24] Add TODO file --- TODO | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..ef57497 --- /dev/null +++ b/TODO @@ -0,0 +1,12 @@ +- add possibility to configure file colors in .zshrc + a) no colors at all for all files + b) one defined colors for all files + c) the same color as path + d) use LS_COLORS + +- separate lsstyle for files and prefix_file? + +- describe in README + a) new STYLES (files, command prefix) + b) how to switch colors (theme) for files + c) how to change color for single file type (via ZSH_HIGHLIGHT_FILES table) From 50695edee62321e23c4d995d5e06e49023645410 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Wed, 24 Sep 2014 16:03:29 +0000 Subject: [PATCH 06/24] TODO update --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index ef57497..8101ff0 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,7 @@ c) the same color as path d) use LS_COLORS +- set different colors for each atom (dir/links) of path - separate lsstyle for files and prefix_file? - describe in README From d69a3685fc65e877fdec1e5fbfeb56a9f6474bff Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 19:26:10 +0000 Subject: [PATCH 07/24] Add description of highlighting style for files to highlighter/main/README.md --- highlighters/main/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index df0c195..2aa9054 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -7,6 +7,7 @@ This is the ***main*** highlighter, that highlights: * Options * Arguments * Paths +* Files * Strings How to activate it @@ -28,6 +29,7 @@ This highlighter defines the following styles: * `builtin` - shell builtin commands * `function` - functions * `command` - commands +* `command_prefix` - command prefixes * `precommand` - precommands (i.e. exec, builtin, ...) * `commandseparator` - command separation tokens * `hashed-command` - hashed commands @@ -58,3 +60,28 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for ZSH_HIGHLIGHT_STYLES[globbing]='none' The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). + + +By default files are colored in the same fashion as `ls` command, namely by comparing file attributes and extension with the content of LS_COLORS environment variable. To override this behaviour change the value of ZSH_HIGHLIGHT_STYLES[file] in ~/.zshrc: + + # To have all files in one color irrespectively of attributes and extensions + ZSH_HIGHLIGHT_STYLES[file]='fg=green' + + # 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' + +It is also possible to change the color for one single file attribute/extenstion. To achieve this modify ZSH_HIGHLIGHT_FILES in ~/.zshrc: + + # To set color for executables + ZSH_HIGHLIGHT_FILES[ex]='fg=119' + + # To set color for files with sticky bit + ZSH_HIGHLIGHT_FILES[st]='fg=7,bg=4' + + # 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. From 7e334e7fe8cf1fce3e4395a89111b4439019a296 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 20:14:45 +0000 Subject: [PATCH 08/24] 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 From 6035534f8c5a505c4cda8e76132618af19a20d56 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 20:56:29 +0000 Subject: [PATCH 09/24] Created small image at misc/screenshot.png and added it to README.md. --- README.md | 2 ++ TODO | 11 ----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7546395..f361404 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ zsh-syntax-highlighting **[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** +![](https://https://github.com/jimmijj/zsh-syntax-highlighting/misc/screenshot.png) + *Requirements: zsh 4.3.17+.* diff --git a/TODO b/TODO index 8101ff0..6331bfa 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,2 @@ -- add possibility to configure file colors in .zshrc - a) no colors at all for all files - b) one defined colors for all files - c) the same color as path - d) use LS_COLORS - - set different colors for each atom (dir/links) of path - separate lsstyle for files and prefix_file? - -- describe in README - a) new STYLES (files, command prefix) - b) how to switch colors (theme) for files - c) how to change color for single file type (via ZSH_HIGHLIGHT_FILES table) From 294c353a029361e45664e2ad32cb31d6c16548ad Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 20:59:01 +0000 Subject: [PATCH 10/24] Add screenshot.png to git --- misc/screenshot.png | Bin 0 -> 7738 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 misc/screenshot.png diff --git a/misc/screenshot.png b/misc/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..e68fadb0412e5c1d6778990283ddfceea32c5708 GIT binary patch literal 7738 zcma)BWl&sAvtAa5APLT*3GPmC3-0a~B)H4sSu{9-AVC+`;O=h0-4@s29{lpYb*t`o z@2`92)O1gus+p>u?&;?|6Rx5pje$mt1^@ssWMw|70RTY5S6vVV_}Wj;r zVgNu@Ec&A<;_H~gOh!!+0Pv;(0KNtT0Qaw^uloRiI~xG-#{>Z2PXPc3oYI?B1z$fP zeU_L01bF$ULE8!wUM;AOQc|w3^7Vn61W5d*D}2>ZJ)Fe8ysq@B0(Ag!KB;s70BN}F zCov81(s72TuZHH**DL`}S(<1r85AmPZ!5}g!37$s*apR=k%+hm2A{;74QJfN77?{o zG$yb#K2_!fQ{a2QMMV8Xi48=hP7ID0A2#Q>elX+cQ5fDX5c_)h$ll?4>ZAPAXV^#C zj~W385v6EE)H%}NH*TeP)v;0jHN6VnOm_6#ex|5*r(zV?D@R4d?tggT*luoy<3+(Z z{16bJtz5hH&rO%=hd|#)!yj^}-|jr^K6p|7N=lpFm1!_H8ZcaA!bd@Hu|n`>$0ZAN zSVyHlqfc)&QstFvdqDfN@(uifw)VbFbcDSLPHr#$iNHtB}YQC6mD zVNDV%ZlV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>)E)e5t4n8vpSLA#|P{}Og9 zCxcV}9~5+++U+8RUmHsI7q3!@Whp;G2``VszARr1Iptfc+dpBnUN5FaZjGU50tXXU zZQc-yZWm=ib$KK+e?;@f7`XIQ8Z&hj@%K&G=DZkjl!8Cws72tV`_k;vmNA1@0EnYK zb<}@shtCj2g_{83hyQm_yh1bqKDUsr(eM?eyq%cu@w_q#TMggJ>Zly4xLaPSTmR6# zSLPO(Au9JIghYVeB#?I}q!s-clM?U7vXwzD_|;7-tAl@7lj3+%{Y2u_zsbh3KwMqJ z7pWabTu=nG;^PfVM$welHqrYK}2zh2J*WF?h8m5ZAM{ue?u*$4mt literal 0 HcmV?d00001 From 5d85b535c720a8a3d9347c6c9e21880f8cc71cc5 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 22:20:42 +0000 Subject: [PATCH 11/24] Small correction in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f361404..edd0c23 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ zsh-syntax-highlighting **[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** -![](https://https://github.com/jimmijj/zsh-syntax-highlighting/misc/screenshot.png) +![](https://raw.githubusercontent.com/jimmijj/zsh-syntax-highlighting/master/misc/screenshot.png) *Requirements: zsh 4.3.17+.* From 5ea0c059779bbf9bd4f775e244a0e3782fce7387 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 26 Sep 2014 23:33:56 +0000 Subject: [PATCH 12/24] TODO mostly done, so deleted --- TODO | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 6331bfa..0000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -- set different colors for each atom (dir/links) of path -- separate lsstyle for files and prefix_file? From a21f6ad6c4f5f9c1477a8a94302ee7622c229433 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 27 Sep 2014 01:22:59 +0000 Subject: [PATCH 13/24] Changed screenshot link in README.md to relative path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edd0c23..18cf308 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ zsh-syntax-highlighting **[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** -![](https://raw.githubusercontent.com/jimmijj/zsh-syntax-highlighting/master/misc/screenshot.png) +![](misc/screenshot.png) *Requirements: zsh 4.3.17+.* From df2041e2d611c93d960c4ef70c75678ddea98dbb Mon Sep 17 00:00:00 2001 From: jimmijj Date: Mon, 29 Sep 2014 13:30:26 +0000 Subject: [PATCH 14/24] Make a few variables local --- highlighters/main/main-highlighter.zsh | 2 +- zsh-syntax-highlighting.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d897c67..77914b0 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -67,7 +67,7 @@ _zsh_highlight_main_highlighter() { emulate -L zsh setopt localoptions extendedglob bareglobqual - local start_pos=0 end_pos highlight_glob=true new_expression=true arg style lsstyle sudo=false sudo_arg=false + local start_pos=0 end_pos highlight_glob=true new_expression=true arg style lsstyle start_file_pos end_file_pos sudo=false sudo_arg=false typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 77b1a8b..b7afae0 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -35,7 +35,6 @@ # Array declaring active highlighters names. typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS -typeset -gA ZSH_HIGHLIGHT_FILES # Update ZLE buffer syntax highlighting. # @@ -107,6 +106,7 @@ _zsh_highlight() # Array used by highlighters to declare user overridable styles. typeset -gA ZSH_HIGHLIGHT_STYLES +typeset -gA ZSH_HIGHLIGHT_FILES # Whether the command line buffer has been modified or not. # From bd2e00a4a99e57e058465421d357f19d80da849b Mon Sep 17 00:00:00 2001 From: jimmijj Date: Tue, 30 Sep 2014 00:45:29 +0000 Subject: [PATCH 15/24] Excluded several widgets from overriding following http://www.zsh.org/mla/users/2014/msg00308.html advise to resolve issue #137 --- zsh-syntax-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index b7afae0..b70743b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -104,7 +104,7 @@ _zsh_highlight() # API/utility functions for highlighters # ------------------------------------------------------------------------------------------------- -# Array used by highlighters to declare user overridable styles. +# Arrays used by highlighters to declare user overridable styles. typeset -gA ZSH_HIGHLIGHT_STYLES typeset -gA ZSH_HIGHLIGHT_FILES @@ -140,7 +140,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*|auto-*|*-argument|argument-base|reset-prompt|split-undo|describe-key-briefly|what-cursor-position|set-local-history)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From 4a82aab57884d6b983ca27ebc646ef908a7a47ad Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 3 Oct 2014 13:01:27 +0000 Subject: [PATCH 16/24] Check for TOKENS_COMMANDSEPARATOR even if $new_expression=false to highlight properly consecutive command separators like 'echo a; ; ; echo b'. --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 77914b0..52e179f 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -134,6 +134,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi From 6d9a34065c7e9d3a68ac0e22262494b45704c982 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 3 Oct 2014 13:17:52 +0000 Subject: [PATCH 17/24] Add condition that path_approx should be highlighted only if $#arg > 3, otherwise it matches too many things. (but do we need path_approx at all?) --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 52e179f..a7227cd 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -209,7 +209,7 @@ _zsh_highlight_main_highlighter_check_path() (( $#tmp > 0 )) && style_override=path_prefix && return 0 # or maybe an approximate path? tmp=( (#a1)${expanded_path}*(N) ) - (( $#tmp > 0 )) && style_override=path_approx && return 0 + (( $#arg > 3 && $#tmp > 0 )) && style_override=path_approx && return 0 fi return 1 } From df99f5f61ae336afb7a19434b7bf74228c4b9fe3 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 3 Oct 2014 17:26:14 +0000 Subject: [PATCH 18/24] Bug fix: when editing multi-line complex command highlighting was shifted by one character starting from second line. This behaviour was due to splitting of BUFFER using shell parser ${(z)BUFFER}, which basically changes all newlines to semicolons. --- highlighters/main/main-highlighter.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a7227cd..b0a1a6d 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -84,12 +84,19 @@ _zsh_highlight_main_highlighter() $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS ) + splitbuf1=(${(z)BUFFER}) + splitbuf2=(${(z)BUFFER//$'\n'/ \$\'\\\\n\' }) # ugly hack, but I have no other idea + local argnum=0 for arg in ${(z)BUFFER}; do + argnum=$((argnum+1)) + if [[ $splitbuf1[$argnum] != $splitbuf2[$argnum] ]] && new_expression=true && continue + local substr_color=0 isfile=false local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}})) ((end_pos=$start_pos+${#arg})) + # Parse the sudo command line if $sudo; then case "$arg" in From f728546b746d5d0b420f4ccf5d2783b7915f8bcd Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 4 Oct 2014 00:36:01 +0000 Subject: [PATCH 19/24] Defined predicate_switcher function in order to be able to use main highlighter when cursor has moved. Normally turning on this feature for the whole main highlighter is not advisable, however it is still helpful in edge cases and solves the problem with highlighting the prefix of the path and file. To prevent slowdown the predicate_switcher is defined in such a way that it activates main highlighter with respect to cursor movement just for one call, and after that returns automatically to the default mode, i.e. highlighting only after buffer is modified. --- highlighters/main/main-highlighter.zsh | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b0a1a6d..00b6a88 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -62,6 +62,31 @@ _zsh_highlight_main_highlighter_predicate() _zsh_highlight_buffer_modified } +## In case we need to highlight in other circumstances then default from highlighter_predicate lets define a switcher +_zsh_highlight_main_highlighter_predicate_switcher() +{ + case $1 in + 'b') # buffer + _zsh_highlight_main_highlighter_predicate() + { + _zsh_highlight_buffer_modified + };; + 'c') # cursor + _zsh_highlight_main_highlighter_predicate() + { + _zsh_highlight_cursor_moved + };; + 'bc') bccounter=0 # buffer and cursor + _zsh_highlight_main_highlighter_predicate() + { + bccounter=$((bccounter+1)) + (( $bccounter > 1 )) && _zsh_highlight_main_highlighter_predicate_switcher b + _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified + };; + *);; + esac +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -213,7 +238,7 @@ _zsh_highlight_main_highlighter_check_path() local -a tmp # got a path prefix? tmp=( ${expanded_path}*(N) ) - (( $#tmp > 0 )) && style_override=path_prefix && return 0 + (( $#tmp > 0 )) && style_override=path_prefix && _zsh_highlight_main_highlighter_predicate_switcher bc && return 0 # or maybe an approximate path? tmp=( (#a1)${expanded_path}*(N) ) (( $#arg > 3 && $#tmp > 0 )) && style_override=path_approx && return 0 @@ -319,6 +344,7 @@ _zsh_highlight_main_highlighter_check_file() [[ -d $expanded_arg ]] && return 1 [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos ]] && matched_file=(${expanded_arg}*(Noa^/[1])) [[ -e $expanded_arg || -e $matched_file ]] && lsstyle=none || return 1 + [[ -e $matched_file ]] && _zsh_highlight_main_highlighter_predicate_switcher bc [[ ! -z $ZSH_HIGHLIGHT_STYLES[file] ]] && lsstyle=$ZSH_HIGHLIGHT_STYLES[file] && return 0 From 25b83ca8a9725aace56ffb6523d2206fbc7b97b4 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 4 Oct 2014 17:12:20 +0000 Subject: [PATCH 20/24] Prevent matching of command prefix if path is written explicitly. This solves issue that prefix '/l' matches '/bin//ls' (with two slashes what is valid syntax for zsh). --- highlighters/main/main-highlighter.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 00b6a88..711cf35 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -171,7 +171,7 @@ _zsh_highlight_main_highlighter() else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi - _zsh_highlight_main_highlighter_check_file && isfile=true + _zsh_highlight_main_highlighter_check_file && isfile=true ;; esac fi @@ -290,6 +290,7 @@ _zsh_highlight_main_highlighter_check_command() { setopt localoptions nonomatch local -a prefixed_command + [[ $arg != $arg:t ]] && return 1 # don't match anything if explicit path is present for p in $path; do prefixed_command+=( $p/${arg}*(N) ); done [[ ${BUFFER[1]} != "-" && ${#LBUFFER} == $end_pos && $#prefixed_command > 0 ]] && return 0 || return 1 } From b85b225dfbd146d2af58c9f148d0462f254627f6 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 17 Jan 2015 17:12:25 +0100 Subject: [PATCH 21/24] Added style for redirection operators. --- highlighters/main/main-highlighter.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 711cf35..3f2cde1 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -40,6 +40,7 @@ : ${ZSH_HIGHLIGHT_STYLES[command_prefix]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} +: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} @@ -94,6 +95,7 @@ _zsh_highlight_main_highlighter() setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true new_expression=true arg style lsstyle start_file_pos end_file_pos sudo=false sudo_arg=false typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR + typeset -a ZSH_HIGHLIGHT_TOKENS_REDIRECTION typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS region_highlight=() @@ -101,6 +103,9 @@ _zsh_highlight_main_highlighter() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' '&|' '|&' '&!' ) + ZSH_HIGHLIGHT_TOKENS_REDIRECTION=( + '<' '<>' '>' '>|' '>!' '>>' '>>|' '>>!' '<<' '<<-' '<<<' '<&' '>&' '<& -' '>& -' '<& p' '>& p' '&>' '>&|' '>&!' '&>|' '&>!' '>>&' '&>>' '>>&|' '>>&!' '&>>|' '&>>!' + ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( 'builtin' 'command' 'exec' 'nocorrect' 'noglob' ) @@ -168,6 +173,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_REDIRECTION:#"$arg"} ]]; then + style=$ZSH_HIGHLIGHT_STYLES[redirection] else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi @@ -193,6 +200,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_REDIRECTION:#"$arg"} ]]; then + style=$ZSH_HIGHLIGHT_STYLES[redirection] else style=$ZSH_HIGHLIGHT_STYLES[default] fi From b0f13404a091b7e60b9f69c3629373af7342888a Mon Sep 17 00:00:00 2001 From: jimmijj Date: Sat, 17 Jan 2015 17:17:23 +0100 Subject: [PATCH 22/24] Added information about redirection operators to README file. --- highlighters/main/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index ed6ddca..7052fdb 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -32,6 +32,7 @@ This highlighter defines the following styles: * `command_prefix` - command prefixes * `precommand` - precommands (i.e. exec, builtin, ...) * `commandseparator` - command separation tokens +* `redirection` - redirection operators * `hashed-command` - hashed commands * `path` - paths * `path_prefix` - path prefixes From 162655841cf709521351124bac06d9475df51633 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Mon, 24 Aug 2015 02:48:54 +0200 Subject: [PATCH 23/24] Reviewed remapped widgets - excluded unnecessary stuff. --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index b70743b..7a86ac9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -140,7 +140,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*|auto-*|*-argument|argument-base|reset-prompt|split-undo|describe-key-briefly|what-cursor-position|set-local-history)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|beep|auto-*|*-argument|argument-base|clear-screen|describe-key-briefly|kill-buffer|overwrite-mode|reset-prompt|set-local-history|split-undo|undefined-key|what-cursor-position|where-is)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From ece762e81798bc4448bf17f68a4792d1117dc032 Mon Sep 17 00:00:00 2001 From: jimmijj Date: Fri, 4 Sep 2015 00:41:02 +0200 Subject: [PATCH 24/24] User's definition of highlighting from "zle_highlight" array should take precedence over custom highlighters. This is especially important for *region context* (see CHARACTER HIGHLIGHTING chapter in `man zshzle` for *region context* definition), as this is overwritten by region_highlight array, leading to highlighting only parts of selected region properly. This commit forces to use type of highlighting as defined in region context of zle_highlight array. --- zsh-syntax-highlighting.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 7a86ac9..265b71f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -90,6 +90,8 @@ _zsh_highlight() # Use value form cache if any cached eval "region_highlight+=(\"\${${cache_place}[@]}\")" + # Bring back region higlighting from zle_highlight array (was overwriten by region_highlight) + ((REGION_ACTIVE)) && region_highlight+=("$((CURSOR < MARK ? CURSOR : MARK)) $((CURSOR > MARK ? CURSOR : MARK)) ${${(M)zle_highlight[@]:#region*}#region:}") done } always {