Merge 69eb765fa3 into cbfd4a8889
				
					
				
			This commit is contained in:
		
						commit
						3402aee95f
					
				| 
						 | 
					@ -28,6 +28,8 @@ This highlighter defines the following styles:
 | 
				
			||||||
* `builtin` - shell builtin commands
 | 
					* `builtin` - shell builtin commands
 | 
				
			||||||
* `function` - functions
 | 
					* `function` - functions
 | 
				
			||||||
* `command` - commands
 | 
					* `command` - commands
 | 
				
			||||||
 | 
					* `precommand` - precommands (i.e. exec, builtin, ...)
 | 
				
			||||||
 | 
					* `commandseparator` - command separation tokens
 | 
				
			||||||
* `hashed-command` - hashed commands
 | 
					* `hashed-command` - hashed commands
 | 
				
			||||||
* `path` - paths
 | 
					* `path` - paths
 | 
				
			||||||
* `globbing` - globbing expressions
 | 
					* `globbing` - globbing expressions
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,8 @@
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
 | 
				
			||||||
 | 
					: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
 | 
				
			||||||
 | 
					: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=fg=green,bold}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
 | 
				
			||||||
| 
						 | 
					@ -50,11 +52,6 @@
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
 | 
				
			||||||
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
 | 
					: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Tokens that are always immediately followed by a command.
 | 
					 | 
				
			||||||
ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=(
 | 
					 | 
				
			||||||
  '|' '||' ';' '&' '&&' 'noglob' 'nocorrect' 'builtin' 'exec'
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Whether the highlighter should be called or not.
 | 
					# Whether the highlighter should be called or not.
 | 
				
			||||||
_zsh_highlight_main_highlighter_predicate()
 | 
					_zsh_highlight_main_highlighter_predicate()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -66,7 +63,22 @@ _zsh_highlight_main_highlighter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  setopt localoptions extendedglob bareglobqual
 | 
					  setopt localoptions extendedglob bareglobqual
 | 
				
			||||||
  local start_pos=0 end_pos highlight_glob=true new_expression=true arg style
 | 
					  local start_pos=0 end_pos highlight_glob=true new_expression=true arg style
 | 
				
			||||||
 | 
					  typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
 | 
				
			||||||
 | 
					  typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
 | 
				
			||||||
 | 
					  typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS
 | 
				
			||||||
  region_highlight=()
 | 
					  region_highlight=()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=(
 | 
				
			||||||
 | 
					    '|' '||' ';' '&' '&&'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
 | 
				
			||||||
 | 
					    'builtin' 'command' 'exec' 'nocorrect' 'noglob'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  # Tokens that are always immediately followed by a command.
 | 
				
			||||||
 | 
					  ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=(
 | 
				
			||||||
 | 
					    $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for arg in ${(z)BUFFER}; do
 | 
					  for arg in ${(z)BUFFER}; do
 | 
				
			||||||
    local substr_color=0
 | 
					    local substr_color=0
 | 
				
			||||||
    [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false
 | 
					    [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false
 | 
				
			||||||
| 
						 | 
					@ -74,6 +86,9 @@ _zsh_highlight_main_highlighter()
 | 
				
			||||||
    ((end_pos=$start_pos+${#arg}))
 | 
					    ((end_pos=$start_pos+${#arg}))
 | 
				
			||||||
    if $new_expression; then
 | 
					    if $new_expression; then
 | 
				
			||||||
      new_expression=false
 | 
					      new_expression=false
 | 
				
			||||||
 | 
					     if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
 | 
				
			||||||
 | 
					      style=$ZSH_HIGHLIGHT_STYLES[precommand]
 | 
				
			||||||
 | 
					     else
 | 
				
			||||||
      res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
 | 
					      res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
 | 
				
			||||||
      case $res in
 | 
					      case $res in
 | 
				
			||||||
        *': reserved')  style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
 | 
					        *': reserved')  style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
 | 
				
			||||||
| 
						 | 
					@ -97,6 +112,7 @@ _zsh_highlight_main_highlighter()
 | 
				
			||||||
                        fi
 | 
					                        fi
 | 
				
			||||||
                        ;;
 | 
					                        ;;
 | 
				
			||||||
      esac
 | 
					      esac
 | 
				
			||||||
 | 
					     fi
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      case $arg in
 | 
					      case $arg in
 | 
				
			||||||
        '--'*)   style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];;
 | 
					        '--'*)   style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];;
 | 
				
			||||||
| 
						 | 
					@ -113,6 +129,8 @@ _zsh_highlight_main_highlighter()
 | 
				
			||||||
                   style=$ZSH_HIGHLIGHT_STYLES[path]
 | 
					                   style=$ZSH_HIGHLIGHT_STYLES[path]
 | 
				
			||||||
                 elif [[ $arg[0,1] = $histchars[0,1] ]]; then
 | 
					                 elif [[ $arg[0,1] = $histchars[0,1] ]]; then
 | 
				
			||||||
                   style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
 | 
					                   style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
 | 
				
			||||||
 | 
					                 elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
 | 
				
			||||||
 | 
					                   style=$ZSH_HIGHLIGHT_STYLES[commandseparator]
 | 
				
			||||||
                 else
 | 
					                 else
 | 
				
			||||||
                   style=$ZSH_HIGHLIGHT_STYLES[default]
 | 
					                   style=$ZSH_HIGHLIGHT_STYLES[default]
 | 
				
			||||||
                 fi
 | 
					                 fi
 | 
				
			||||||
| 
						 | 
					@ -135,9 +153,9 @@ _zsh_highlight_main_highlighter_check_assign()
 | 
				
			||||||
# Check if the argument is a path.
 | 
					# Check if the argument is a path.
 | 
				
			||||||
_zsh_highlight_main_highlighter_check_path()
 | 
					_zsh_highlight_main_highlighter_check_path()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  [[ -z ${(Q)~arg} ]] && return 1
 | 
					  [[ -z "${(Q)~arg}" ]] && return 1
 | 
				
			||||||
  [[ -e ${(Q)~arg} ]] && return 0
 | 
					  [[ -e "${(Q)~arg}" ]] && return 0
 | 
				
			||||||
  [[ ! -e ${(Q)~arg:h} ]] && return 1
 | 
					  [[ ! -e "${(Q)~arg:h}" ]] && return 1
 | 
				
			||||||
  [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print "${(Q)~arg}"*(N)) ]] && return 0
 | 
					  [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print "${(Q)~arg}"*(N)) ]] && return 0
 | 
				
			||||||
  return 1
 | 
					  return 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue