From 4b6fbaa22172aa9e48653511d463182d1ceef540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Thu, 30 Jan 2014 23:54:16 -0500 Subject: [PATCH 1/4] highlight path separators --- highlighters/main/main-highlighter.zsh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 72b48f0..d0ae014 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,6 +41,7 @@ : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_separator]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} @@ -127,6 +128,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[assign] new_expression=true elif _zsh_highlight_main_highlighter_check_path; then + _zsh_highlight_main_highlighter_highlight_path_separators style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] @@ -149,6 +151,7 @@ _zsh_highlight_main_highlighter() '`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then + _zsh_highlight_main_highlighter_highlight_path_separators style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] @@ -175,6 +178,19 @@ _zsh_highlight_main_highlighter_check_assign() [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])=* ]] } +_zsh_highlight_main_highlighter_highlight_path_separators() +{ + local pos style + style=$ZSH_HIGHLIGHT_STYLES[path_separator] + for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do + local char="$BUFFER[pos+1]" + + if [[ "$char" == "/" ]]; then + region_highlight+=("$pos $((pos + 1)) $style") + fi + done +} + # Check if the argument is a path. _zsh_highlight_main_highlighter_check_path() { From 84527c2257dee98c618833c778e24fccd872b013 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Fri, 31 Jan 2014 19:00:46 +0100 Subject: [PATCH 2/4] more efficient implementation Thanks to m0viefreak! Conflicts: highlighters/main/main-highlighter.zsh --- highlighters/main/main-highlighter.zsh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d0ae014..99a43c4 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -45,6 +45,10 @@ : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} +: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=fg=cyan,underline} +: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=fg=cyan,underline} +: ${ZSH_HIGHLIGHT_STYLES[path_approx_pathseparator]:=fg=cyan,underline} +: ${ZSH_HIGHLIGHT_STYLES[globbing_pathseparator]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} @@ -86,6 +90,7 @@ _zsh_highlight_main_highlighter() for arg in ${(z)BUFFER}; do local substr_color=0 local style_override="" + local path_found= [[ $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})) @@ -128,8 +133,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[assign] new_expression=true elif _zsh_highlight_main_highlighter_check_path; then - _zsh_highlight_main_highlighter_highlight_path_separators style=$ZSH_HIGHLIGHT_STYLES[path] + path_found=path elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] else @@ -151,8 +156,8 @@ _zsh_highlight_main_highlighter() '`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then - _zsh_highlight_main_highlighter_highlight_path_separators style=$ZSH_HIGHLIGHT_STYLES[path] + path_found=path elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then @@ -166,6 +171,7 @@ _zsh_highlight_main_highlighter() # 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] [[ $substr_color = 0 ]] && region_highlight+=("$start_pos $end_pos $style") + [[ -n $path_found ]] && _zsh_highlight_main_highlighter_highlight_path_separators [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true start_pos=$end_pos done @@ -191,6 +197,18 @@ _zsh_highlight_main_highlighter_highlight_path_separators() done } +_zsh_highlight_main_highlighter_highlight_path_separators() +{ + local pos style + style=$ZSH_HIGHLIGHT_STYLES[${style_override:=${path_found}}_pathseparator] + [[ -z $style ]] && return 0 + for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do + if [[ $BUFFER[pos+1] == / ]]; then + region_highlight+=("$pos $((pos + 1)) $style") + fi + done +} + # Check if the argument is a path. _zsh_highlight_main_highlighter_check_path() { From af03935a598a4bd888be0b128be54adaad6a62b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Sat, 1 Feb 2014 00:35:36 -0500 Subject: [PATCH 3/4] clean up the merge --- highlighters/main/main-highlighter.zsh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 99a43c4..6528e8c 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,7 +41,6 @@ : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} -: ${ZSH_HIGHLIGHT_STYLES[path_separator]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} @@ -184,19 +183,6 @@ _zsh_highlight_main_highlighter_check_assign() [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])=* ]] } -_zsh_highlight_main_highlighter_highlight_path_separators() -{ - local pos style - style=$ZSH_HIGHLIGHT_STYLES[path_separator] - for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do - local char="$BUFFER[pos+1]" - - if [[ "$char" == "/" ]]; then - region_highlight+=("$pos $((pos + 1)) $style") - fi - done -} - _zsh_highlight_main_highlighter_highlight_path_separators() { local pos style From 3350c4ad4c28d9a4cdc05e33911aa95e95c990de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Thu, 25 Sep 2014 10:01:58 -0700 Subject: [PATCH 4/4] document new path separator styles --- highlighters/main/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index df0c195..a1ab78c 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -34,7 +34,11 @@ This highlighter defines the following styles: * `path` - paths * `path_prefix` - path prefixes * `path_approx` - approximated paths +* `path_pathseparator` - path separator +* `path_prefix_pathseparator` - path prefixes' path separator +* `path_approx_pathseparator` - approximated paths' path separator * `globbing` - globbing expressions +* `globbing_pathseparator` - globs' path separator * `history-expansion` - history expansion expressions * `single-hyphen-option` - single hyphen options * `double-hyphen-option` - double hyphen options