diff options
| author | kj-sh604 | 2025-07-16 22:10:52 -0400 |
|---|---|---|
| committer | kj-sh604 | 2025-07-16 22:10:52 -0400 |
| commit | 1e204d36c1fab9884f65618ccca019d8cd5f9386 (patch) | |
| tree | 962ebadaa02a15d2f8441b290daf330bfbd48417 /.config/shell/zsh-fast-syntax-highlighting/fast-highlight | |
| parent | 7c9e54b5366ada655baf8c2b61914182840d6bb6 (diff) | |
refactor: update `zsh-fast-syntax-highlighting` plugin
Diffstat (limited to '.config/shell/zsh-fast-syntax-highlighting/fast-highlight')
| -rw-r--r-- | .config/shell/zsh-fast-syntax-highlighting/fast-highlight | 295 |
1 files changed, 170 insertions, 125 deletions
diff --git a/.config/shell/zsh-fast-syntax-highlighting/fast-highlight b/.config/shell/zsh-fast-syntax-highlighting/fast-highlight index c410c23..d82df20 100644 --- a/.config/shell/zsh-fast-syntax-highlighting/fast-highlight +++ b/.config/shell/zsh-fast-syntax-highlighting/fast-highlight @@ -33,7 +33,10 @@ typeset -g FAST_WORK_DIR : ${FAST_WORK_DIR:=$FAST_BASE_DIR} FAST_WORK_DIR=${~FAST_WORK_DIR} () { - setopt localoptions extendedglob + # We must not use emulate -o if we want to keep compatibility with Zsh < v.5.0 + # See https://github.com/zdharma-continuum/fast-syntax-highlighting/pull/7 + emulate -L zsh + setopt extendedglob local -A map map=( "XDG:" "${XDG_CONFIG_HOME:-$HOME/.config}/fsh/" "LOCAL:" "/usr/local/share/fsh/" @@ -107,7 +110,7 @@ zstyle :plugin:fast-syntax-highlighting theme default : ${FAST_HIGHLIGHT_STYLES[incorrect-subtle]:=fg=red} : ${FAST_HIGHLIGHT_STYLES[subtle-separator]:=fg=green} : ${FAST_HIGHLIGHT_STYLES[subtle-bg]:=bg=18} -: ${FAST_HIGHLIGHT_STYLES[secondary]:=} +: ${FAST_HIGHLIGHT_STYLES[secondary]:=free} fi # This can overwrite some of *_STYLES fields @@ -165,107 +168,115 @@ typeset -gA FAST_HIGHLIGHT : ${FAST_HIGHLIGHT[use_brackets]:=1} FAST_HIGHLIGHT+=( - chroma-fast-theme :chroma/-fast-theme.ch - chroma-alias :chroma/-alias.ch - chroma-autoload :chroma/-autoload.ch - chroma-autorandr :chroma/-autorandr.ch - chroma-docker :chroma/-docker.ch - chroma-example :chroma/-example.ch - chroma-ionice :chroma/-ionice.ch - chroma-make :chroma/-make.ch - chroma-nice :chroma/-nice.ch - chroma-nmcli :chroma/-nmcli.ch - chroma-node :chroma/-node.ch - chroma-perl :chroma/-perl.ch - chroma-printf :chroma/-printf.ch - chroma-ruby :chroma/-ruby.ch - chroma-scp :chroma/-scp.ch - chroma-ssh :chroma/-ssh.ch - - chroma-git :chroma/main-chroma.ch%git - chroma-hub :chroma/-hub.ch - chroma-lab :chroma/-lab.ch - chroma-svn :chroma/-subversion.ch - chroma-svnadmin :chroma/-subversion.ch - chroma-svndumpfilter :chroma/-subversion.ch - - chroma-egrep :chroma/-grep.ch - chroma-fgrep :chroma/-grep.ch - chroma-grep :chroma/-grep.ch - - chroma-awk :chroma/-awk.ch - chroma-gawk :chroma/-awk.ch - chroma-mawk :chroma/-awk.ch - - chroma-source :chroma/-source.ch - chroma-. :chroma/-source.ch - - chroma-bash :chroma/-sh.ch - chroma-fish :chroma/-sh.ch - chroma-sh :chroma/-sh.ch - chroma-zsh :chroma/-sh.ch - - chroma-whatis :chroma/-whatis.ch - chroma-man :chroma/-whatis.ch - - chroma-- :chroma/-precommand.ch - chroma-xargs :chroma/-precommand.ch - chroma-nohup :chroma/-precommand.ch - - chroma-hg :chroma/-subcommand.ch - chroma-cvs :chroma/-subcommand.ch - chroma-pip :chroma/-subcommand.ch - chroma-pip2 :chroma/-subcommand.ch - chroma-pip3 :chroma/-subcommand.ch - chroma-gem :chroma/-subcommand.ch - chroma-bundle :chroma/-subcommand.ch - chroma-yard :chroma/-subcommand.ch - chroma-cabal :chroma/-subcommand.ch - chroma-npm :chroma/-subcommand.ch - chroma-nvm :chroma/-subcommand.ch - chroma-yarn :chroma/-subcommand.ch - chroma-brew :chroma/-subcommand.ch - chroma-port :chroma/-subcommand.ch - chroma-yum :chroma/-subcommand.ch - chroma-dnf :chroma/-subcommand.ch - chroma-tmux :chroma/-subcommand.ch - chroma-pass :chroma/-subcommand.ch - chroma-aws :chroma/-subcommand.ch - chroma-apt :chroma/-subcommand.ch - chroma-apt-get :chroma/-subcommand.ch - chroma-apt-cache :chroma/-subcommand.ch - chroma-aptitude :chroma/-subcommand.ch - chroma-keyctl :chroma/-subcommand.ch - chroma-systemctl :chroma/-subcommand.ch - chroma-asciinema :chroma/-subcommand.ch - chroma-ipfs :chroma/-subcommand.ch - chroma-zplugin :chroma/main-chroma.ch%zplugin - chroma-aspell :chroma/-subcommand.ch - chroma-bspc :chroma/-subcommand.ch - chroma-cryptsetup :chroma/-subcommand.ch - chroma-diskutil :chroma/-subcommand.ch - chroma-exercism :chroma/-subcommand.ch - chroma-gulp :chroma/-subcommand.ch - chroma-i3-msg :chroma/-subcommand.ch - chroma-openssl :chroma/-subcommand.ch - chroma-solargraph :chroma/-subcommand.ch - chroma-subliminal :chroma/-subcommand.ch - chroma-svnadmin :chroma/-subcommand.ch - chroma-travis :chroma/-subcommand.ch - chroma-udisksctl :chroma/-subcommand.ch - chroma-xdotool :chroma/-subcommand.ch - chroma-zmanage :chroma/-subcommand.ch - chroma-zsystem :chroma/-subcommand.ch - chroma-zypper :chroma/-subcommand.ch - - chroma-fpath+=\( :chroma/-fpath_peq.ch - chroma-fpath=\( :chroma/-fpath_peq.ch - chroma-FPATH+= :chroma/-fpath_peq.ch - chroma-FPATH= :chroma/-fpath_peq.ch - #chroma-which :chroma/-which.ch - #chroma-vim :chroma/-vim.ch + chroma-fast-theme →chroma/-fast-theme.ch + chroma-alias →chroma/-alias.ch + chroma-autoload →chroma/-autoload.ch + chroma-autorandr →chroma/-autorandr.ch + chroma-docker →chroma/-docker.ch + chroma-example →chroma/-example.ch + chroma-ionice →chroma/-ionice.ch + chroma-make →chroma/-make.ch + chroma-nice →chroma/-nice.ch + chroma-nmcli →chroma/-nmcli.ch + chroma-node →chroma/-node.ch + chroma-perl →chroma/-perl.ch + chroma-podman →chroma/-podman.ch + chroma-printf →chroma/-printf.ch + chroma-ruby →chroma/-ruby.ch + chroma-scp →chroma/-scp.ch + chroma-ssh →chroma/-ssh.ch + + chroma-git →chroma/main-chroma.ch%git + chroma-hub →chroma/-hub.ch + chroma-lab →chroma/-lab.ch + chroma-svn →chroma/-subversion.ch + chroma-svnadmin →chroma/-subversion.ch + chroma-svndumpfilter →chroma/-subversion.ch + + chroma-egrep →chroma/-grep.ch + chroma-fgrep →chroma/-grep.ch + chroma-grep →chroma/-grep.ch + + chroma-awk →chroma/-awk.ch + chroma-gawk →chroma/-awk.ch + chroma-goawk →chroma/-awk.ch + chroma-mawk →chroma/-awk.ch + + chroma-source →chroma/-source.ch + chroma-. →chroma/-source.ch + + chroma-bash →chroma/-sh.ch + chroma-fish →chroma/-sh.ch + chroma-sh →chroma/-sh.ch + chroma-zsh →chroma/-sh.ch + + chroma-whatis →chroma/-whatis.ch + chroma-man →chroma/-whatis.ch + + chroma-- →chroma/-precommand.ch + chroma-xargs →chroma/-precommand.ch + chroma-nohup →chroma/-precommand.ch + chroma-strace →chroma/-precommand.ch + chroma-ltrace →chroma/-precommand.ch + + chroma-hg →chroma/-subcommand.ch + chroma-cvs →chroma/-subcommand.ch + chroma-pip →chroma/-subcommand.ch + chroma-pip2 →chroma/-subcommand.ch + chroma-pip3 →chroma/-subcommand.ch + chroma-gem →chroma/-subcommand.ch + chroma-bundle →chroma/-subcommand.ch + chroma-yard →chroma/-subcommand.ch + chroma-cabal →chroma/-subcommand.ch + chroma-npm →chroma/-subcommand.ch + chroma-nvm →chroma/-subcommand.ch + chroma-yarn →chroma/-subcommand.ch + chroma-brew →chroma/-subcommand.ch + chroma-port →chroma/-subcommand.ch + chroma-yum →chroma/-subcommand.ch + chroma-dnf →chroma/-subcommand.ch + chroma-tmux →chroma/-subcommand.ch + chroma-pass →chroma/-subcommand.ch + chroma-aws →chroma/-subcommand.ch + chroma-apt →chroma/-subcommand.ch + chroma-apt-get →chroma/-subcommand.ch + chroma-apt-cache →chroma/-subcommand.ch + chroma-aptitude →chroma/-subcommand.ch + chroma-keyctl →chroma/-subcommand.ch + chroma-systemctl →chroma/-subcommand.ch + chroma-asciinema →chroma/-subcommand.ch + chroma-ipfs →chroma/-subcommand.ch + chroma-zinit →chroma/main-chroma.ch%zinit + chroma-aspell →chroma/-subcommand.ch + chroma-bspc →chroma/-subcommand.ch + chroma-cryptsetup →chroma/-subcommand.ch + chroma-diskutil →chroma/-subcommand.ch + chroma-exercism →chroma/-subcommand.ch + chroma-gulp →chroma/-subcommand.ch + chroma-i3-msg →chroma/-subcommand.ch + chroma-openssl →chroma/-subcommand.ch + chroma-solargraph →chroma/-subcommand.ch + chroma-subliminal →chroma/-subcommand.ch + chroma-svnadmin →chroma/-subcommand.ch + chroma-travis →chroma/-subcommand.ch + chroma-udisksctl →chroma/-subcommand.ch + chroma-xdotool →chroma/-subcommand.ch + chroma-zmanage →chroma/-subcommand.ch + chroma-zsystem →chroma/-subcommand.ch + chroma-zypper →chroma/-subcommand.ch + + chroma-fpath+=\( →chroma/-fpath_peq.ch + chroma-fpath=\( →chroma/-fpath_peq.ch + chroma-FPATH+= →chroma/-fpath_peq.ch + chroma-FPATH= →chroma/-fpath_peq.ch + #chroma-which →chroma/-which.ch + #chroma-vim →chroma/-vim.ch ) +if [[ $OSTYPE == darwin* ]] { + noglob unset FAST_HIGHLIGHT[chroma-man] FAST_HIGHLIGHT[chroma-whatis] +} + # Assignments seen, to know if math parameter exists typeset -gA FAST_ASSIGNS_SEEN @@ -288,7 +299,7 @@ typeset -ga ZLAST_COMMANDS if zmodload -e zsh/parameter; then if (( $+aliases[(e)$1] )); then REPLY=alias - elif (( ${+galiases[(e)$1]} )); then + elif (( ${+galiases[(e)${(Q)1}]} )); then REPLY="global alias" elif (( $+functions[(e)$1] )); then REPLY=function @@ -360,7 +371,7 @@ typeset -ga ZLAST_COMMANDS -fast-highlight-process() { emulate -L zsh - setopt extendedglob bareglobqual nonomatch noksharrays typesetsilent + setopt extendedglob bareglobqual nonomatch typesetsilent [[ $CONTEXT == "select" ]] && return 0 @@ -434,9 +445,9 @@ typeset -ga ZLAST_COMMANDS FAST_HIGHLIGHT[chroma-autoload-elements]="" # Restart FPATH elements gathering FAST_HIGHLIGHT[chroma-fpath_peq-elements]="" - # Restart svn zplugin's ICE gathering - FAST_HIGHLIGHT[chroma-zplugin-ice-elements-svn]=0 - FAST_HIGHLIGHT[chroma-zplugin-ice-elements-id-as]="" + # Restart svn zinit's ICE gathering + FAST_HIGHLIGHT[chroma-zinit-ice-elements-svn]=0 + FAST_HIGHLIGHT[chroma-zinit-ice-elements-id-as]="" [[ -n $ZCALC_ACTIVE ]] && { _start_pos=0; _end_pos=__len; __arg=$__buf @@ -629,11 +640,13 @@ typeset -ga ZLAST_COMMANDS [[ $__arg = "[[" ]] && __style=${FAST_THEME_NAME}double-sq-bracket || __style=${FAST_THEME_NAME}reserved-word if [[ $__arg == $'\x7b' ]]; then # Y - '{' braces_stack='Y'$braces_stack + elif [[ $__arg == $'\x7d' && $braces_stack = Y* ]]; then # Y - '}' # We're at command word, so no need to check right_brace_is_recognised_everywhere braces_stack=${braces_stack#Y} __style=${FAST_THEME_NAME}reserved-word (( next_word = next_word | 16 )) + elif [[ $__arg == "[[" ]]; then # A - [[ braces_stack='A'$braces_stack @@ -641,14 +654,17 @@ typeset -ga ZLAST_COMMANDS _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN + 1 )) ) elif [[ $__arg == "for" ]]; then (( next_word = next_word | 32 )) # BIT_for + elif [[ $__arg == "case" ]]; then (( next_word = BIT_case_preamble )) + elif [[ $__arg = (typeset|declare|local|float|integer|export|readonly) ]]; then braces_stack='T'$braces_stack fi ;; 'suffix alias') __style=${FAST_THEME_NAME}suffix-alias;; 'global alias') __style=${FAST_THEME_NAME}global-alias;; + alias) if [[ $__arg = ?*'='* ]]; then # The so called (by old code) "insane_alias" @@ -659,6 +675,7 @@ typeset -ga ZLAST_COMMANDS [[ ${__FAST_HIGHLIGHT_TOKEN_TYPES[$alias_target]} = "1" && $__arg_type != "1" ]] && __FAST_HIGHLIGHT_TOKEN_TYPES[$__arg]="1" fi ;; + builtin) [[ $__arg = "[" ]] && { __style=${FAST_THEME_NAME}single-sq-bracket _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) ) @@ -667,12 +684,17 @@ typeset -ga ZLAST_COMMANDS [[ $__arg = (typeset|declare|local|float|integer|export|readonly) ]] && braces_stack='T'$braces_stack [[ $__arg = eval ]] && (( next_word = next_word | 256 )) ;; + function) __style=${FAST_THEME_NAME}function;; + command) __style=${FAST_THEME_NAME}command;; + hashed) __style=${FAST_THEME_NAME}hashed-command;; + dirpath) __style=${FAST_THEME_NAME}path-to-dir;; + none) # Assign? - if [[ $__arg == [a-zA-Z_][a-zA-Z0-9_]#(|\[[^\]]#\])(|[^\]]#\])(|[+])=* || $__arg == [0-9]##(|[+])=* || ( $braces_stack = T* && ${__arg_type} != 3 ) ]]; then + if [[ $__arg == [a-zA-Z_][a-zA-Z0-9_]#(|\[[^\]]#\])(|[^\]]#\])(|[+])=* || $__arg == [0-9]##(|[+])=* || ( $braces_stack = T* && ${__arg_type} != 3 ) ]] { __style=${FAST_THEME_NAME}assign FAST_ASSIGNS_SEEN[${__arg%%=*}]=1 @@ -716,15 +738,19 @@ typeset -ga ZLAST_COMMANDS } || -fast-highlight-string; (( _start_pos = _start_pos - itmp + 1, 1 > 0 )) } - elif [[ $__arg = ${histchars[1]}* && -n ${__arg[2]} ]]; then + + } elif [[ $__arg = ${histchars[1]}* && -n ${__arg[2]} ]] { __style=${FAST_THEME_NAME}history-expansion - elif [[ $__arg == ${histchars[2]}* ]]; then + + } elif [[ $__arg == ${histchars[2]}* ]] { __style=${FAST_THEME_NAME}history-expansion - elif (( __arg_type == 3 )); then + + } elif (( __arg_type == 3 )) { # This highlights empty commands (semicolon follows nothing) as an error. # Zsh accepts them, though. (( this_word & 3 )) && __style=${FAST_THEME_NAME}commandseparator - elif [[ $__arg[1,2] == '((' ]]; then + + } elif [[ $__arg[1,2] == '((' ]] { # Arithmetic evaluation. # # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...} @@ -752,25 +778,30 @@ typeset -ga ZLAST_COMMANDS # Counting complex brackets (for brackets-highlighter): 7. )) for as-command (( _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) ) } - elif [[ $__arg == '()' ]]; then + + } elif [[ $__arg == '()' ]] { _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN + 1 )) ) # anonymous function __style=${FAST_THEME_NAME}reserved-word - elif [[ $__arg == $'\x28' ]]; then + } elif [[ $__arg == $'\x28' ]] { # subshell '(', stack: letter 'R' __style=${FAST_THEME_NAME}reserved-word braces_stack='R'$braces_stack - elif [[ $__arg == $'\x29' ]]; then + + } elif [[ $__arg == $'\x29' ]] { # ')', stack: letter 'R' for subshell [[ $braces_stack = R* ]] && { braces_stack=${braces_stack#R}; __style=${FAST_THEME_NAME}reserved-word; } - elif (( this_word & 14 )); then + + } elif (( this_word & 14 )) { __style=${FAST_THEME_NAME}default - elif [[ $__arg = (';;'|';&'|';|') ]] && (( this_word & BIT_case_code )); then + + } elif [[ $__arg = (';;'|';&'|';|') ]] && (( this_word & BIT_case_code )) { (( next_word = (next_word | BIT_case_item) & ~(BIT_case_code+3) )) __style=${FAST_THEME_NAME}default - elif [[ $__arg = \$\([^\(]* ]]; then + + } elif [[ $__arg = \$\([^\(]* ]] { already_added=1 - fi + } ;; *) # ADD @@ -1035,7 +1066,7 @@ typeset -ga ZLAST_COMMANDS __style=${FAST_THEME_NAME}commandseparator elif (( in_redirection == 2 )); then __style=${FAST_THEME_NAME}redirection - elif (( ${+galiases[(e)$__arg]} )); then + elif (( ${+galiases[(e)${(Q)__arg}]} )); then __style=${FAST_THEME_NAME}global-alias else if [[ ${FAST_HIGHLIGHT[no_check_paths]} != 1 ]]; then @@ -1119,6 +1150,18 @@ typeset -ga ZLAST_COMMANDS fi fi fi + if [[ $__arg = (#b)*'#'(([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])|([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F]))(|[^[:alnum:]]*) || $__arg = (#b)*'rgb('(([0-9a-fA-F][0-9a-fA-F](#c0,1)),([0-9a-fA-F][0-9a-fA-F](#c0,1)),([0-9a-fA-F][0-9a-fA-F](#c0,1)))* ]]; then + if [[ -n $match[2] ]]; then + if [[ $match[2] = ?? || $match[3] = ?? || $match[4] = ?? ]]; then + (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end bg=#${(l:2::0:)match[2]}${(l:2::0:)match[3]}${(l:2::0:)match[4]}") + else + (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end bg=#$match[2]$match[3]$match[4]") + fi + else + (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end bg=#$match[5]$match[6]$match[7]") + fi + already_added=1 + fi # ADD (( already_added == 0 )) && [[ ${FAST_HIGHLIGHT_STYLES[$__style]} != "none" ]] && (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}") @@ -1373,10 +1416,12 @@ zle -N -- fast-highlight-check-path-handler -fast-highlight-check-path-handler local i j k __style local AA integer c + # Starting dollar-quote is at 1:2, so __start parsing at offset 3 in the string. for (( i = 3 ; i < _end_pos - _start_pos ; i += 1 )) ; do (( j = i + _start_pos - 1 )) (( k = j + 1 )) + case ${__arg[$i]} in "\\") __style=${FAST_THEME_NAME}back-dollar-quoted-argument for (( c = i + 1 ; c <= _end_pos - _start_pos ; c += 1 )); do @@ -1384,13 +1429,13 @@ zle -N -- fast-highlight-check-path-handler -fast-highlight-check-path-handler done AA=$__arg[$i+1,$c-1] # Matching for HEX and OCT values like \0xA6, \xA6 or \012 - if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}" - || "$AA" =~ "^[0-7]{1,3}" - || "$AA" =~ "^u[0-9a-fA-F]{1,4}" - || "$AA" =~ "^U[0-9a-fA-F]{1,8}" + if [[ "$AA" == (#m)(#s)(x|X)[0-9a-fA-F](#c1,2) + || "$AA" == (#m)(#s)[0-7](#c1,3) + || "$AA" == (#m)(#s)u[0-9a-fA-F](#c1,4) + || "$AA" == (#m)(#s)U[0-9a-fA-F](#c1,8) ]]; then - (( k += $#MATCH )) - (( i += $#MATCH )) + (( k += MEND )) + (( i += MEND )) else if (( __asize > i+1 )) && [[ $__arg[i+1] == [xXuU] ]]; then # \x not followed by hex digits is probably an error |
