mirror of
				https://github.com/zsh-users/zsh-syntax-highlighting.git
				synced 2025-11-03 19:45:46 +00:00 
			
		
		
		
	aliases: Highlight aliases with '=' in their LHS as error. (Part of issue #263.)
This commit is contained in:
		
							parent
							
								
									5e4b446dee
								
							
						
					
					
						commit
						28932316cc
					
				@ -294,9 +294,28 @@ _zsh_highlight_main_highlighter()
 | 
			
		||||
        *': suffix alias')
 | 
			
		||||
                        style=$ZSH_HIGHLIGHT_STYLES[suffix-alias]
 | 
			
		||||
                        ;;
 | 
			
		||||
        *': alias')     style=$ZSH_HIGHLIGHT_STYLES[alias]
 | 
			
		||||
                        local aliased_command="${"$(alias -- $arg)"#*=}"
 | 
			
		||||
                        [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
 | 
			
		||||
        *': alias')     () {
 | 
			
		||||
                          integer insane_alias
 | 
			
		||||
                          case $arg in 
 | 
			
		||||
                            # Issue #263: aliases with '=' on their LHS.
 | 
			
		||||
                            #
 | 
			
		||||
                            # There are three cases:
 | 
			
		||||
                            #
 | 
			
		||||
                            # - Unsupported, breaks 'alias -L' output, but invokable:
 | 
			
		||||
                            ('='*) :;;
 | 
			
		||||
                            # - Unsupported, not invokable:
 | 
			
		||||
                            (*'='*) insane_alias=1;;
 | 
			
		||||
                            # - The common case:
 | 
			
		||||
                            (*) :;;
 | 
			
		||||
                          esac
 | 
			
		||||
                          if (( insane_alias )); then
 | 
			
		||||
                            style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
 | 
			
		||||
                          else
 | 
			
		||||
                            style=$ZSH_HIGHLIGHT_STYLES[alias]
 | 
			
		||||
                            local aliased_command="${"$(alias -- $arg)"#*=}"
 | 
			
		||||
                            [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
 | 
			
		||||
                          fi
 | 
			
		||||
                        }
 | 
			
		||||
                        ;;
 | 
			
		||||
        *': builtin')   style=$ZSH_HIGHLIGHT_STYLES[builtin];;
 | 
			
		||||
        *': function')  style=$ZSH_HIGHLIGHT_STYLES[function];;
 | 
			
		||||
 | 
			
		||||
@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight
 | 
			
		||||
BUFFER='x=y ls'
 | 
			
		||||
 | 
			
		||||
expected_region_highlight=(
 | 
			
		||||
  "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token] 'issue #263, #issuecomment-170579803'" # x=y
 | 
			
		||||
  "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # x=y
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user