From 390ab0fc32cd22f0b8db0ebb52d1da51d5166218 Mon Sep 17 00:00:00 2001 From: NAKAMURA Yoshitaka Date: Mon, 14 Feb 2011 19:23:23 +0900 Subject: [PATCH] Highlight variable assignment --- zsh-syntax-highlighting.zsh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 68fc33f..c33cda9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -53,6 +53,7 @@ ZSH_HIGHLIGHT_STYLES=( dollar-double-quoted-argument 'fg=cyan' back-double-quoted-argument 'fg=cyan' bracket-error 'fg=red,bold' + assign 'none' ) # Colors for bracket levels. @@ -77,6 +78,12 @@ zle_highlight=( isearch:$ZSH_HIGHLIGHT_STYLES[isearch] ) +# Check if the argument is variable assignment +_zsh_check-assign() { + setopt localoptions extended_glob + [[ ${(Q)arg} == [[:alpha:]_]([[:alnum:]_])#=* ]] +} + # Check if the argument is a path. _zsh_check-path() { [[ -z ${(Q)arg} ]] && return 1 @@ -139,7 +146,10 @@ _zsh_highlight-zle-buffer() { *': function') style=$ZSH_HIGHLIGHT_STYLES[function];; *': command') style=$ZSH_HIGHLIGHT_STYLES[command];; *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; - *) if _zsh_check-path; then + *) if _zsh_check-assign; then + style=$ZSH_HIGHLIGHT_STYLES[assign] + new_expression=true + elif _zsh_check-path; then style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion]