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 diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5b038b4..ec7f350 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -44,6 +44,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} @@ -85,6 +89,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,6 +133,7 @@ _zsh_highlight_main_highlighter() new_expression=true elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] + path_found=path elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] else @@ -150,6 +156,7 @@ _zsh_highlight_main_highlighter() *"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then 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 @@ -163,6 +170,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 @@ -175,6 +183,18 @@ _zsh_highlight_main_highlighter_check_assign() [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])=* ]] } +_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() {