From aed99f6a3e9f29859682d92003731c75e43362e8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 30 Sep 2015 18:56:35 +0000 Subject: [PATCH 01/84] wrappers: Reimplement using Mikachu's zle-line-pre-redraw hook (workers/36650). --- zsh-syntax-highlighting.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4caf3a8..02d45f9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,6 +49,11 @@ if true; then fi fi +integer zsh_highlight_use_redrawhook +if zle -la .match-bracket; then + (( zsh_highlight_use_redrawhook=1 )) +fi + # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- @@ -357,6 +362,11 @@ _zsh_highlight_bind_widgets() done } +if (( $zsh_highlight_use_redrawhook )); then + _zsh_highlight_bind_widgets(){} + zle -N zle-line-pre-redraw _zsh_highlight +fi + # Load highlighters from directory. # # Arguments: From 85e62a81716e194a91ed1e9c78cac45e5cba4fa6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jun 2016 23:26:23 +0000 Subject: [PATCH 02/84] driver: Reimplement using 'add-zle-hook-widget zle-line-pre-redraw' This feature will be released in zsh 5.3. Older zsh's will use the existing codepath. --- zsh-syntax-highlighting.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 02d45f9..8476c1a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -50,7 +50,9 @@ if true; then fi integer zsh_highlight_use_redrawhook -if zle -la .match-bracket; then +if autoload -U +X -- add-zle-hook-widget 2>/dev/null; + [[ "${${(@f)"$(which -- add-zle-hook-widget)"}[2]}" != $'\t'$histchars[3]' undefined' ]]; +then (( zsh_highlight_use_redrawhook=1 )) fi @@ -364,7 +366,9 @@ _zsh_highlight_bind_widgets() if (( $zsh_highlight_use_redrawhook )); then _zsh_highlight_bind_widgets(){} - zle -N zle-line-pre-redraw _zsh_highlight + if [[ -o zle ]]; then + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + fi fi # Load highlighters from directory. From 74a27de70d7d21e92a50a6398a5eeeb12b884a4f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 29 Jul 2016 20:32:29 +0000 Subject: [PATCH 03/84] driver: Hook zle-line-finish. Compare issue #288. --- zsh-syntax-highlighting.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 8476c1a..1f5b827 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -365,9 +365,20 @@ _zsh_highlight_bind_widgets() } if (( $zsh_highlight_use_redrawhook )); then + _zsh_highlight__zle-line-finish() { + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # A nested function is required to hide zle parameters; see + # "User-defined widgets" in zshall. + () { + local -h +r WIDGET=zle-line-finish + _zsh_highlight "$@" + } + } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish fi fi From 30c6e7039453c9f62b52caac1d202f57c48be442 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 24 Aug 2016 22:56:09 +0000 Subject: [PATCH 04/84] driver: Pass zle-line-finish arguments on to _zsh_highlight. (Currently a noop) --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 1f5b827..4769255 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -373,7 +373,7 @@ if (( $zsh_highlight_use_redrawhook )); then () { local -h +r WIDGET=zle-line-finish _zsh_highlight "$@" - } + } "$@" } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then From 04fd6bbf53a637129f9a11137314d74d0e103d8a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 04:41:51 +0000 Subject: [PATCH 05/84] changelog: Note the effect of fixing #245/#90 and an alternative. --- changelog.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/changelog.md b/changelog.md index f20e69d..33cd461 100644 --- a/changelog.md +++ b/changelog.md @@ -292,6 +292,27 @@ in this area. (0a9b347483ae) +# Changes in version 0.5.0 + + +## Incompatible changes: + +- An unsuccessful completion (a ⮀ Tab press that doesn't change the + command line) no longer causes highlighting to be lost. Visual feedback can + alternatively be achieved by setting the `format` zstyle under the `warnings` + tag, for example, + + zstyle ':completion:*:warnings' format '%F{red}No matches%f' + + Refer to the [description of the `format` style in `zshcompsys(1)`] + [zshcompsys-Standard-Styles]. + + (#90, part of #245, XXXXXXXXXXXX) + +[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles + + + # Changes in version 0.4.1 ## Fixes: From d98622dcd03cf3714e0679f13582e56ebb3a8f22 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 04:45:05 +0000 Subject: [PATCH 06/84] changelog: Use a more specific link. --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 33cd461..6ed90f1 100644 --- a/changelog.md +++ b/changelog.md @@ -305,11 +305,12 @@ in this area. zstyle ':completion:*:warnings' format '%F{red}No matches%f' Refer to the [description of the `format` style in `zshcompsys(1)`] - [zshcompsys-Standard-Styles]. + [zshcompsys-Standard-Styles-format]. (#90, part of #245, XXXXXXXXXXXX) [zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style From 38477f2a3d3ffd06ec2b7496d18cc97d6ee0c4bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 03:23:08 +0000 Subject: [PATCH 07/84] driver: Use a different way of checking whether add-zle-hook-widget is present. Based on code by Bart Schaefer (reference within). Tested with zsh 5.0.7-5 (debian package) and with 5b4cbcc842c6 (39158, 5.3-to-be of today). --- zsh-syntax-highlighting.zsh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4769255..dd28bc7 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,10 +49,37 @@ if true; then fi fi +# This function takes a single argument F and returns True iff F denotes the +# name of a callable function. A function is callable if it is fully defined +# or if it is marked for autoloading and autoloading it at the first call to it +# will succeed. In particular, if a function has been marked for autoloading +# but is not available in $fpath, then this function will return False therefor. +# +# See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 +_zsh_highlight__function_callable_p() { + { # Trenary condition: if the zle/parameter module is available, ... + if (( ${+functions} )); then + # ... then use it to make the decision, ... + if (( ${+functions[$1]} )); then + [[ "$functions[$1]" != *"builtin autoload -X" ]] \ + || + ( unfunction -- "$1" && autoload -U +X -- "$1" 2>/dev/null ) + else + ( autoload -U +X -- "$1" 2>/dev/null ) + fi + else + # ... otherwise, use a fallback approach. + autoload -U +X -- "$1" 2>/dev/null + [[ "${${(@f)"$(which -- "$1")"}[2]}" != $'\t'$histchars[3]' undefined' ]] + fi + } + # Do nothing here! We return the exit code of the if. +} + integer zsh_highlight_use_redrawhook -if autoload -U +X -- add-zle-hook-widget 2>/dev/null; - [[ "${${(@f)"$(which -- add-zle-hook-widget)"}[2]}" != $'\t'$histchars[3]' undefined' ]]; +if _zsh_highlight__function_callable_p add-zle-hook-widget then + autoload -U add-zle-hook-widget (( zsh_highlight_use_redrawhook=1 )) fi From d4ab7e51d2f0d1231221e87e3f5899104bf1f0ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 16 Sep 2016 04:34:59 +0000 Subject: [PATCH 08/84] redo _zsh_highlight__function_callable_p --- zsh-syntax-highlighting.zsh | 51 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index dd28bc7..4aa7b99 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,6 +49,25 @@ if true; then fi fi +# This function takes a single argument F and returns True iff F is an autoload stub. +_zsh_highlight__function_is_autoload_stub_p() { + if (( ${+functions} )); then + ## zsh/parameter is available + #(( ${+functions[$1]} )) && + [[ "$functions[$1]" == *"builtin autoload -X" ]] + else + ## zsh/parameter isn't available + #[[ $(type -wa -- "$1") == *'function'* ]] && + [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] + fi + # Do nothing here: return the exit code of the if. +} + +# Return True iff the argument denotes a function name. +_zsh_highlight__is_function_p() { + (( ${+functions[$1]} )) || [[ $(type -wa -- "$1") == *'function'* ]] +} + # This function takes a single argument F and returns True iff F denotes the # name of a callable function. A function is callable if it is fully defined # or if it is marked for autoloading and autoloading it at the first call to it @@ -57,23 +76,21 @@ fi # # See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { - { # Trenary condition: if the zle/parameter module is available, ... - if (( ${+functions} )); then - # ... then use it to make the decision, ... - if (( ${+functions[$1]} )); then - [[ "$functions[$1]" != *"builtin autoload -X" ]] \ - || - ( unfunction -- "$1" && autoload -U +X -- "$1" 2>/dev/null ) - else - ( autoload -U +X -- "$1" 2>/dev/null ) - fi - else - # ... otherwise, use a fallback approach. - autoload -U +X -- "$1" 2>/dev/null - [[ "${${(@f)"$(which -- "$1")"}[2]}" != $'\t'$histchars[3]' undefined' ]] - fi - } - # Do nothing here! We return the exit code of the if. + if _zsh_highlight__is_function_p "$1" && + ! _zsh_highlight__function_is_autoload_stub_p "$1" + then + # Already fully loaded. + return 0 # true + else + # "$1" is either an autoload stub, or not a function at all. + # + # Use a subshell to avoid affecting the calling shell. + # + # We expect 'autoload +X' to return non-zero if it fails to fully load + # the function. + ( autoload -U +X -- "$1" 2>/dev/null ) + return $? + fi } integer zsh_highlight_use_redrawhook From 1651137f5ca9673e4d40b43d8bcea450e10ec9f9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 7 Oct 2016 14:21:57 +0000 Subject: [PATCH 09/84] docs: Update FAQ answer per changes on this branch. --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08af2b6..34b5ef1 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,23 @@ FAQ ### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file? -`zsh-syntax-highlighting.zsh` wraps ZLE widgets. It must be sourced after all +zsh-syntax-highlighting works by hooking into the Zsh Line Editor (ZLE) and +computing syntax highlighting for the command-line buffer as it stands at the +time z-sy-h's hook is invoked. + +In zsh 5.2 and older, +`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must be sourced after all custom widgets have been created (i.e., after all `zle -N` calls and after -running `compinit`). Widgets created later will work, but will not update the +running `compinit`) in order to be able to wrap all of them. +Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. +In zsh 5.3 and newer, +zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install +a `zle-line-pre-redraw` hook. Hooks are run in order of registration, +therefore, z-sy-h must be sourced (and register its hook) after anything else +that adds hooks that modify the command-line buffer. + ### Does syntax highlighting work during incremental history search? Highlighting the command line during an incremental history search (by default bound to From 66ae59ecccffb31722e4924028ae4949c3380af2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 7 Oct 2016 14:22:23 +0000 Subject: [PATCH 10/84] docs: Rewrap. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34b5ef1..dbfc8b8 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ computing syntax highlighting for the command-line buffer as it stands at the time z-sy-h's hook is invoked. In zsh 5.2 and older, -`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must be sourced after all -custom widgets have been created (i.e., after all `zle -N` calls and after -running `compinit`) in order to be able to wrap all of them. +`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must +be sourced after all custom widgets have been created (i.e., after all `zle -N` +calls and after running `compinit`) in order to be able to wrap all of them. Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. From d2594c115796a90e548c3249684bc5ce5fdfb68e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 14:49:53 +0000 Subject: [PATCH 11/84] noop: Make a whitespace-only change to reduce noise in the next commit. --- zsh-syntax-highlighting.zsh | 132 ++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4aa7b99..5e16fd2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -337,76 +337,78 @@ _zsh_highlight_add_highlight() # $1 is name of widget to call _zsh_highlight_call_widget() { - builtin zle "$@" && + builtin zle "$@" && _zsh_highlight } -# Rebind all ZLE widgets to make them invoke _zsh_highlights. -_zsh_highlight_bind_widgets() -{ - setopt localoptions noksharrays - typeset -F SECONDS - local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once +if true; then + # Rebind all ZLE widgets to make them invoke _zsh_highlights. + _zsh_highlight_bind_widgets() + { + setopt localoptions noksharrays + typeset -F SECONDS + local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once - # Load ZSH module zsh/zleparameter, needed to override user defined widgets. - zmodload zsh/zleparameter 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' - return 1 + # Load ZSH module zsh/zleparameter, needed to override user defined widgets. + zmodload zsh/zleparameter 2>/dev/null || { + print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' + return 1 + } + + # Override ZLE widgets to make them invoke _zsh_highlight. + local -U widgets_to_bind + widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)}) + + # Always wrap special zle-line-finish widget. This is needed to decide if the + # current line ends and special highlighting logic needs to be applied. + # E.g. remove cursor imprint, don't highlight partial paths, ... + widgets_to_bind+=(zle-line-finish) + + # Always wrap special zle-isearch-update widget to be notified of updates in isearch. + # This is needed because we need to disable highlighting in that case. + widgets_to_bind+=(zle-isearch-update) + + local cur_widget + for cur_widget in $widgets_to_bind; do + case ${widgets[$cur_widget]:-""} in + + # Already rebound event: do nothing. + user:_zsh_highlight_widget_*);; + + # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function + # definition time is used. + # + # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with + # NO_function_argzero, regardless of the option's setting here. + + # User defined widget: override and rebind old one with prefix "orig-". + user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Completion widget: override and rebind old one with prefix "orig-". + completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Builtin widget: override and make it call the builtin ".widget". + builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Incomplete or nonexistent widget: Bind to z-sy-h directly. + *) + if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then + _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } + zle -N $cur_widget _zsh_highlight_widget_$cur_widget + else + # Default: unhandled case. + print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" + print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)" + fi + esac + done } - - # Override ZLE widgets to make them invoke _zsh_highlight. - local -U widgets_to_bind - widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)}) - - # Always wrap special zle-line-finish widget. This is needed to decide if the - # current line ends and special highlighting logic needs to be applied. - # E.g. remove cursor imprint, don't highlight partial paths, ... - widgets_to_bind+=(zle-line-finish) - - # Always wrap special zle-isearch-update widget to be notified of updates in isearch. - # This is needed because we need to disable highlighting in that case. - widgets_to_bind+=(zle-isearch-update) - - local cur_widget - for cur_widget in $widgets_to_bind; do - case ${widgets[$cur_widget]:-""} in - - # Already rebound event: do nothing. - user:_zsh_highlight_widget_*);; - - # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function - # definition time is used. - # - # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with - # NO_function_argzero, regardless of the option's setting here. - - # User defined widget: override and rebind old one with prefix "orig-". - user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Incomplete or nonexistent widget: Bind to z-sy-h directly. - *) - if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then - _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } - zle -N $cur_widget _zsh_highlight_widget_$cur_widget - else - # Default: unhandled case. - print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" - print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)" - fi - esac - done -} +fi if (( $zsh_highlight_use_redrawhook )); then _zsh_highlight__zle-line-finish() { From b5249f17abe4850ae3a6fa9130b3be78923e41dc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 15:12:24 +0000 Subject: [PATCH 12/84] driver: Rewrite without a state variable Suggested-by: m0viefreak --- zsh-syntax-highlighting.zsh | 45 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 5e16fd2..f020b33 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -93,13 +93,6 @@ _zsh_highlight__function_callable_p() { fi } -integer zsh_highlight_use_redrawhook -if _zsh_highlight__function_callable_p add-zle-hook-widget -then - autoload -U add-zle-hook-widget - (( zsh_highlight_use_redrawhook=1 )) -fi - # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- @@ -341,7 +334,25 @@ _zsh_highlight_call_widget() _zsh_highlight } -if true; then +if _zsh_highlight__function_callable_p add-zle-hook-widget +then + autoload -U add-zle-hook-widget + _zsh_highlight__zle-line-finish() { + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # A nested function is required to hide zle parameters; see + # "User-defined widgets" in zshall. + () { + local -h +r WIDGET=zle-line-finish + _zsh_highlight "$@" + } "$@" + } + _zsh_highlight_bind_widgets(){} + if [[ -o zle ]]; then + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish + fi +else # Rebind all ZLE widgets to make them invoke _zsh_highlights. _zsh_highlight_bind_widgets() { @@ -410,24 +421,6 @@ if true; then } fi -if (( $zsh_highlight_use_redrawhook )); then - _zsh_highlight__zle-line-finish() { - # Reset $WIDGET since the 'main' highlighter depends on it. - # - # A nested function is required to hide zle parameters; see - # "User-defined widgets" in zshall. - () { - local -h +r WIDGET=zle-line-finish - _zsh_highlight "$@" - } "$@" - } - _zsh_highlight_bind_widgets(){} - if [[ -o zle ]]; then - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight - add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish - fi -fi - # Load highlighters from directory. # # Arguments: From a868b6942ea017dcd09cdcd6461d27825838364e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 17:51:04 +0000 Subject: [PATCH 13/84] test harness: Actually test the new code. Currently, without zsh/zle loaded, the tests silently fall back to the 5.2-and-earlier codepath; see: . https://github.com/zsh-users/zsh-syntax-highlighting/pull/356#issuecomment-243651251 --- tests/generate.zsh | 3 +++ tests/test-highlighting.zsh | 3 +++ tests/test-perfs.zsh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/generate.zsh b/tests/generate.zsh index 64a1ede..ef89f94 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -31,6 +31,9 @@ emulate -LR zsh setopt localoptions extendedglob +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Argument parsing. if (( $# != 3 )) || [[ $1 == -* ]]; then print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 812b1a7..e5c85a1 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -31,6 +31,9 @@ setopt NO_UNSET WARN_CREATE_GLOBAL +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 3411754..49d95c7 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -29,6 +29,9 @@ # ------------------------------------------------------------------------------------------------- +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." From f665eec230e66cc62f0c6a02cc63dc13e3124e5c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jan 2018 05:44:54 +0000 Subject: [PATCH 14/84] driver: Avoid a fork in the common case. Found-by: Matthew Martin --- zsh-syntax-highlighting.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f020b33..04152c4 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -65,7 +65,13 @@ _zsh_highlight__function_is_autoload_stub_p() { # Return True iff the argument denotes a function name. _zsh_highlight__is_function_p() { - (( ${+functions[$1]} )) || [[ $(type -wa -- "$1") == *'function'* ]] + if (( ${+functions} )); then + ## zsh/parameter is available + (( ${+functions[$1]} )) + else + ## zsh/parameter isn't available + [[ $(type -wa -- "$1") == *'function'* ]] + fi } # This function takes a single argument F and returns True iff F denotes the From d0fb0df4ff96209d6623896f07be7db2655cf1b4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jan 2018 06:03:38 +0000 Subject: [PATCH 15/84] driver: Make the shadowing $WIDGET read only. --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 04152c4..6fb1c12 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -349,7 +349,7 @@ then # A nested function is required to hide zle parameters; see # "User-defined widgets" in zshall. () { - local -h +r WIDGET=zle-line-finish + local -h -r WIDGET=zle-line-finish _zsh_highlight "$@" } "$@" } From f265ef0b9aadfea02c696821664c8598f5809b91 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 8 Jan 2018 12:35:45 -0600 Subject: [PATCH 16/84] driver: Use idiomatic module check --- zsh-syntax-highlighting.zsh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 6fb1c12..c03c434 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -51,12 +51,10 @@ fi # This function takes a single argument F and returns True iff F is an autoload stub. _zsh_highlight__function_is_autoload_stub_p() { - if (( ${+functions} )); then - ## zsh/parameter is available + if zmodload -e zsh/parameter; then #(( ${+functions[$1]} )) && [[ "$functions[$1]" == *"builtin autoload -X" ]] else - ## zsh/parameter isn't available #[[ $(type -wa -- "$1") == *'function'* ]] && [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] fi @@ -65,11 +63,9 @@ _zsh_highlight__function_is_autoload_stub_p() { # Return True iff the argument denotes a function name. _zsh_highlight__is_function_p() { - if (( ${+functions} )); then - ## zsh/parameter is available + if zmodload -e zsh/parameter; then (( ${+functions[$1]} )) else - ## zsh/parameter isn't available [[ $(type -wa -- "$1") == *'function'* ]] fi } From 2cbb3fb24ecf0880165f57d823746e2f257c3619 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 8 Jan 2018 12:59:56 -0600 Subject: [PATCH 17/84] driver: Allow for -U in autoloaded function definition --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index c03c434..17ce59c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -53,7 +53,7 @@ fi _zsh_highlight__function_is_autoload_stub_p() { if zmodload -e zsh/parameter; then #(( ${+functions[$1]} )) && - [[ "$functions[$1]" == *"builtin autoload -X" ]] + [[ "$functions[$1]" == *"builtin autoload -X"* ]] else #[[ $(type -wa -- "$1") == *'function'* ]] && [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] From 56ba7f082d171102deaeb35a14e900ab1a6a6495 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 9 Jan 2018 19:23:45 +0000 Subject: [PATCH 18/84] driver: Clarify comment. No functional change. --- zsh-syntax-highlighting.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 17ce59c..9dc6c1f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -342,8 +342,9 @@ then _zsh_highlight__zle-line-finish() { # Reset $WIDGET since the 'main' highlighter depends on it. # - # A nested function is required to hide zle parameters; see - # "User-defined widgets" in zshall. + # Since $WIDGET is declared by zle as read-only in this function's scope, + # a nested function is required in order to shadow its built-in value; + # see "User-defined widgets" in zshall. () { local -h -r WIDGET=zle-line-finish _zsh_highlight "$@" From 8d4c6355e6d252f1d67beca4df946f8335fac51c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 21:55:45 -0500 Subject: [PATCH 19/84] driver: Do not pass widget arguments to _zsh_highlight This avoids a bug in zsh 4.3.12 and prior which affects passing arguments to an anonymous function. --- zsh-syntax-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 9dc6c1f..aa650d3 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -347,8 +347,8 @@ then # see "User-defined widgets" in zshall. () { local -h -r WIDGET=zle-line-finish - _zsh_highlight "$@" - } "$@" + _zsh_highlight + } } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then From b08d508cd8792df2b6c8e044e42dffeb7f9118fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 15:49:24 +0000 Subject: [PATCH 20/84] driver: Fix a bug that prevented subsequent, third-party zle-line-pre-redraw hooks from running. Without this patch, `_zsh_highlight` was invoked by add-zle-hook-widget with `$?` being non-zero (see add-zle-hook-widget:48-52). Since `_zsh_highlight` preserves `$?` from its caller's point of view, add-zle-hook-widget saw a non-zero exit code from `_zsh_highlight` and did not run any the remaining zle-line-pre-redraw hooks. See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-623576907. --- zsh-syntax-highlighting.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index aa650d3..47a4e07 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -350,9 +350,15 @@ then _zsh_highlight } } + _zsh_highlight__zle-line-pre-redraw() { + # Set $? to 0 for _zsh_highlight. Without this, subsequent + # zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to + # call us with $? == 1 in the common case. + true && _zsh_highlight "$@" + } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight__zle-line-pre-redraw add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish fi else From daf0d94baedab4f8bf76dbfb0bcdae3dba005e11 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:00:45 +0000 Subject: [PATCH 21/84] On the feature/redrawhook branch, move the changelog entry to the current release's section. --- changelog.md | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index 280f434..7951f38 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,25 @@ added to zsh at z-sy-h's initiative. The new feature is used in the fix to issue #418. +## Incompatible changes: + +- An unsuccessful completion (a ⮀ Tab press that doesn't change the + command line) no longer causes highlighting to be lost. Visual feedback can + alternatively be achieved by setting the `format` zstyle under the `warnings` + tag, for example, + + zstyle ':completion:*:warnings' format '%F{red}No matches%f' + + Refer to the [description of the `format` style in `zshcompsys(1)`] + [zshcompsys-Standard-Styles-format]. + + (#90, part of #245 (feature/redrawhook)) + +[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style + + + ## Other changes: - Document `$ZSH_HIGHLIGHT_MAXLENGTH`. @@ -485,28 +504,6 @@ in this area. (0a9b347483ae) -# Changes in version 0.5.0 - - -## Incompatible changes: - -- An unsuccessful completion (a ⮀ Tab press that doesn't change the - command line) no longer causes highlighting to be lost. Visual feedback can - alternatively be achieved by setting the `format` zstyle under the `warnings` - tag, for example, - - zstyle ':completion:*:warnings' format '%F{red}No matches%f' - - Refer to the [description of the `format` style in `zshcompsys(1)`] - [zshcompsys-Standard-Styles-format]. - - (#90, part of #245, XXXXXXXXXXXX) - -[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles -[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style - - - # Changes in version 0.4.1 ## Fixes: From 59cb9a560d3b2acdb21c666d09ff43411c2153a0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:13:51 +0000 Subject: [PATCH 22/84] driver: Make the redrawhook codepath conditional upon the memo= feature. Fixes #579 (zsh-autosuggestions interoperability). Fixes #735 (ditto). See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-650126055 See https://github.com/zsh-users/zsh-autosuggestions/issues/529#issuecomment-650481227 --- 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 c2811a0..87ffb6a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -403,7 +403,17 @@ _zsh_highlight_call_widget() _zsh_highlight } -if _zsh_highlight__function_callable_p add-zle-hook-widget +# Decide whether to use the zle-line-pre-redraw codepath (colloquially known as +# "feature/redrawhook", after the topic branch's name) or the legacy "bind all +# widgets" codepath. +# +# We use the new codepath under two conditions: +# +# 1. If it's available, which we check by testing for add-zle-hook-widget's availability. +# +# 2. If zsh has the memo= feature, which is required for interoperability reasons. +# See issues #579 and #735, and the issues referenced from them. +if (( zsh_highlight__memo_feature )) && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From cb33cc0081234c0f8e48d89e0ba81cf58a8f7635 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:37:41 +0000 Subject: [PATCH 23/84] On the feature/redrawhook branch, change the detection of the 'memo=' feature to avoid a catch-22. --- zsh-syntax-highlighting.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index cbdd530..3608203 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -407,7 +407,14 @@ _zsh_highlight_call_widget() # # 2. If zsh has the memo= feature, which is required for interoperability reasons. # See issues #579 and #735, and the issues referenced from them. -if (( zsh_highlight__memo_feature )) && _zsh_highlight__function_callable_p add-zle-hook-widget +# +# We check this with a plain version number check, since a functional check, +# as done by _zsh_highlight, can only be done from inside a widget +# function — a catch-22. +# +# See _zsh_highlight for the magic version number. (The use of 5.8.0.2 +# rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) +if is-at-least 5.8.0.2 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From 2d60a47cc407117815a1d7b331ef226aa400a344 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 24/84] Post-release version number bump. --- .version | 2 +- changelog.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 41c20b3..9fb1210 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0-alpha1-pre-redrawhook +0.8.0-alpha2-dev diff --git a/changelog.md b/changelog.md index 96ad507..518d6a8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +# Changes in HEAD + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility From cba4a1bc2e62833a4f5631b89e0974585db39103 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 23:20:29 +0000 Subject: [PATCH 25/84] On the feature/redrawhook branch, changelog: Add entries for issues fixed by this branch. This covers issues referenced from #245 or labelled "feature:redrawhook" or "widget-wrapping". See #749 for details. --- changelog.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/changelog.md b/changelog.md index 44ddbe0..1bc1ac0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,57 @@ # Changes in HEAD +## Changes fixed as part of the switch to zle-line-pre-redraw + +The changes in this section were fixed by switching to a `zle-line-pre-redraw`-based +implementation. + +Note: The new implementation will only be used on future zsh releases, +numbered 5.8.0.3 and newer, due to interoperability issues with other plugins +(issues #418 and #579). The underlying zsh feature has been available since +zsh 5.2. + +Whilst under development, the new implementation was known as the +"feature/redrawhook" topic branch. + +- Fixed: Highlighting not triggered after popping a buffer from the buffer stack + (using the `push-line` widget, default binding: `M-q`) + [#40] + +- Fixed: Invoking completion when there were no matches removed highlighting + [#90, #470] + +- Fixed: Two successive deletes followed by a yank only yanked the latest + delete, rather than both of them + [#150, #151, #160; cf. #183] + +- Presumed fixed: Completing `$(xsel)` results in an error message from `xsel`, + with pre-2017 versions of `xsel`. (For 2017 vintage and newer, see the issue + for details.) + [#154] + +- Fixed: When the standard `bracketed-paste-magic` widget is in use, pastes were slow + [#295] + +- Fixed: No way to prevent a widget from being wrapped + [#324] + +- Fixed: No highlighting while cycling menu completion + [#375] + +- Fixed: Does not coexist with the `IGNORE_EOF` option + [#377] + +- Fixed: The `undefined-key` widget was wrapped + [#421] + +- Fixed: Does not coexist with the standard `surround` family of widgets + [#520] + +- Fixed: First completed filename doesn't get `path` highlighting + [#632] + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility From 7cc6226477a46e7f8217239686912c9cc4a7696b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 9 Aug 2020 10:54:01 +0000 Subject: [PATCH 26/84] docs: Track making the new codepath conditional upon the 'memo=' feature. The new codepath is used in 5.8.0.2 and newer; see zsh-syntax-highlighting.zsh:417. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52896c0..303ee1e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ calls and after running `compinit`) in order to be able to wrap all of them. Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. -In zsh 5.3 and newer, +In zsh newer than 5.8 (not including 5.8 itself), zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install a `zle-line-pre-redraw` hook. Hooks are run in order of registration, therefore, z-sy-h must be sourced (and register its hook) after anything else From c14fcad3b08e19dce750b4b0eb6cc597e0f93d57 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 9 Aug 2020 11:09:19 +0000 Subject: [PATCH 27/84] empty commit: Close redrawhook bugs The parent commit, which merged the feature/redrawhook bug and thereby closed PR #749, also fixed the following issue: Fixes #40. Fixes #90, closes #470. (The latter is a PR for the former.) Fixes #150, closes #151, closes #160. (The latter two are PR's for the first one.) The related issue #183 appears to have been fixed in master. For #150, a different fix for older versions of zsh was considered but has not been implemented. Issue #154 was fixed in xsel(1) in 2017. The parent commit probably fixed that issue for pre-2017 xsel(1). Is #245, #356, and #749. Fixes #245 (redrawhook umbrella issue). Does not reintroduce #257 (comment). Does not reintroduce #259 (comment) Closes #281 as obsolete. Fixes #295. Fixes #324. Fixes #375. Fixes #377. Closes #421 as obsolete. Fixes #520. Unblocks #536 (already milestoned). Fixes #632. Unblocks #635. Milestoned. Unblocks #688. Milestoned. Unblocks administrative issue #655 (already milestoned). (The above is copied from https://github.com/zsh-users/zsh-syntax-highlighting/pull/749#issuecomment-658407330, but repeated here for the sake of github's commit-to-issue linking magic.) From e4d1db1e2cf2f0bb6158408e8adf3c9938f2f8df Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Jul 2020 23:23:20 -0500 Subject: [PATCH 28/84] docs: Sort INSTALL.md --- INSTALL.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index fc0f752..834cdae 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,21 +9,21 @@ How to install * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] -* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) -* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) * Void Linux: `zsh-syntax-highlighting package` [in XBPS][void-package] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git -[debian-package]: https://packages.debian.org/zsh-syntax-highlighting -[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ -[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb -[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting +[debian-package]: https://packages.debian.org/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting +[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ +[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting +[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) From 34674d7860ea34bad2bdc4afc8beb8af6dc245a8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Jul 2020 23:23:58 -0500 Subject: [PATCH 29/84] docs: Add OpenBSD port --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 834cdae..49b8ce5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,6 +9,7 @@ How to install * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) @@ -23,6 +24,7 @@ How to install [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting +[openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting From 3944a44ffe447b64d4bc55a1ff66154363bb0dd6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 10 Aug 2020 07:36:40 +0000 Subject: [PATCH 30/84] driver: Fix a version number check to work around a bug in the zsh version whereunder the check should return false. The bug is as follows: % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 && echo yes || echo no' yes % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION && echo yes || echo no' yes This commit deploys the following workaround: % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && echo yes || echo no' no Fixes #756. --- zsh-syntax-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 3608203..d20dc5b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -163,7 +163,7 @@ _zsh_highlight() # On zsh version 5.8.0.2 between the aforementioned commit and the # first Config/version.mk bump after it (which, at the time of writing, # is yet to come), this condition will false negative. - if is-at-least 5.8.0.3; then + if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -414,7 +414,7 @@ _zsh_highlight_call_widget() # # See _zsh_highlight for the magic version number. (The use of 5.8.0.2 # rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) -if is-at-least 5.8.0.2 && _zsh_highlight__function_callable_p add-zle-hook-widget +if is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From 79b6e7e05f96f777244686be513b2e583b6143f6 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 9 Aug 2020 21:58:48 +0200 Subject: [PATCH 31/84] tests: precommand-killing1: Use a dummy path that always exists E.g., on Cygwin /etc/passwd does not necessarily exist. --- highlighters/main/test-data/precommand-killing1.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/precommand-killing1.zsh b/highlighters/main/test-data/precommand-killing1.zsh index 80d279b..7598346 100644 --- a/highlighters/main/test-data/precommand-killing1.zsh +++ b/highlighters/main/test-data/precommand-killing1.zsh @@ -29,11 +29,12 @@ # ------------------------------------------------------------------------------------------------- hash sudo=false +touch foo -BUFFER='sudo -e /etc/passwd' +BUFFER='sudo -e ./foo' expected_region_highlight=( '1 4 precommand' # sudo '6 7 single-hyphen-option' # -e - '9 19 path' # /etc/passwd + '9 13 path' # ./foo ) From e9cad1493fe1ef85945df66af2a5e015cfaebea8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 11 Aug 2020 08:42:59 +0000 Subject: [PATCH 32/84] changelog: Document #712 under the last tag, 0.8.0-alpha1-pre-redrawhook. --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 1bc1ac0..9230236 100644 --- a/changelog.md +++ b/changelog.md @@ -52,6 +52,11 @@ Whilst under development, the new implementation was known as the [#632] +## Other changes + +- Add issue #712 to the previous release's changelog (hereinafter). + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility @@ -187,6 +192,9 @@ to issue #418. - Improve performance of the `brackets` highlighter. +- Fix highlighting of pre-command redirections (e.g., the `$fn` in `<$fn cat`) + [#712] + # Changes in version 0.7.1 From 6d5372a937c63a565a1ff93aa6efa9a2b6179917 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 11 Aug 2020 09:21:21 +0000 Subject: [PATCH 33/84] tests: parameter-to-global-alias: Fix a false positive failure when 'x' happens to be a valid external command name. Reported on issue #757 along with other issues. --- highlighters/main/test-data/parameter-to-global-alias.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh index 2c4b9bb..cd2283b 100644 --- a/highlighters/main/test-data/parameter-to-global-alias.zsh +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -28,6 +28,10 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +if type x >/dev/null; then + skip_test="Test is written on the assumption that 'x' is not a valid command name, but that assumption does not hold" + return 0 +fi alias -g x=y local s=x From 4cf464f843902b6e1e2778b85b70f4c098789b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivo=20=C5=A0merek?= Date: Sat, 15 Aug 2020 12:24:09 +0200 Subject: [PATCH 34/84] docs: Update Gentoo link --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 49b8ce5..0ca2295 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -7,7 +7,7 @@ How to install * Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] (or in [OBS repository][obs-repository]) * Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository]) * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) -* Gentoo: [mv overlay][gentoo-overlay] +* Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] @@ -22,7 +22,7 @@ How to install [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ -[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting +[gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting [openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting From 62c5575848f1f0a96161243d18497c247c9f52df Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Wed, 26 Aug 2020 08:46:53 +0000 Subject: [PATCH 35/84] tests: Add a test that 'rehash' isn't run. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See comments within for the rationale. This is a regression test for a regression that was only present in development versions of PR #764 and was never present in master. --- highlighters/main/test-data/no-rehash.zsh | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/no-rehash.zsh diff --git a/highlighters/main/test-data/no-rehash.zsh b/highlighters/main/test-data/no-rehash.zsh new file mode 100644 index 0000000..ca11414 --- /dev/null +++ b/highlighters/main/test-data/no-rehash.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +hash zsyh-hashed-command=/usr/bin/env +BUFFER='doesnotexist; zsyh-hashed-command' + +# Test that highlighting "doesnotexist" does not invoke the "rehash" builtin, +# which would delete hashed commands (such as "zsyh-hashed-command"). +expected_region_highlight=( + "1 12 unknown-token" # doesnotexist + "13 13 commandseparator" # ; + "15 33 hashed-command" # zsyh-hashed-command +) From aac09942b86934b5d4467225d7336f495c466d10 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 12 Oct 2020 19:28:53 -0500 Subject: [PATCH 36/84] Revert "tests: Add a test that 'rehash' isn't run." This reverts commit 62c5575848f1f0a96161243d18497c247c9f52df. The test fails when zsh/parameter is available. --- highlighters/main/test-data/no-rehash.zsh | 39 ----------------------- 1 file changed, 39 deletions(-) delete mode 100644 highlighters/main/test-data/no-rehash.zsh diff --git a/highlighters/main/test-data/no-rehash.zsh b/highlighters/main/test-data/no-rehash.zsh deleted file mode 100644 index ca11414..0000000 --- a/highlighters/main/test-data/no-rehash.zsh +++ /dev/null @@ -1,39 +0,0 @@ -# ------------------------------------------------------------------------------------------------- -# Copyright (c) 2020 zsh-syntax-highlighting contributors -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, are permitted -# provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of conditions -# and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, this list of -# conditions and the following disclaimer in the documentation and/or other materials provided -# with the distribution. -# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors -# may be used to endorse or promote products derived from this software without specific prior -# written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ------------------------------------------------------------------------------------------------- -# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# vim: ft=zsh sw=2 ts=2 et -# ------------------------------------------------------------------------------------------------- - -hash zsyh-hashed-command=/usr/bin/env -BUFFER='doesnotexist; zsyh-hashed-command' - -# Test that highlighting "doesnotexist" does not invoke the "rehash" builtin, -# which would delete hashed commands (such as "zsyh-hashed-command"). -expected_region_highlight=( - "1 12 unknown-token" # doesnotexist - "13 13 commandseparator" # ; - "15 33 hashed-command" # zsyh-hashed-command -) From 2ebfa6a59879b66b02712693731c84831255601d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 8 Oct 2020 19:35:12 -0500 Subject: [PATCH 37/84] main: Forget seen aliases when starting a new command Fixes #769 --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/alias-reuse1.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse2.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse3.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse4.zsh | 42 +++++++++++++++++++ highlighters/main/test-data/alias-reuse5.zsh | 43 ++++++++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 highlighters/main/test-data/alias-reuse1.zsh create mode 100644 highlighters/main/test-data/alias-reuse2.zsh create mode 100644 highlighters/main/test-data/alias-reuse3.zsh create mode 100644 highlighters/main/test-data/alias-reuse4.zsh create mode 100644 highlighters/main/test-data/alias-reuse5.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e59c61c..2a29d0d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -879,6 +879,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' highlight_glob=true saw_assignment=false + seen_alias=() if [[ $arg != '|' && $arg != '|&' ]]; then next_word+=':start_of_pipeline:' fi diff --git a/highlighters/main/test-data/alias-reuse1.zsh b/highlighters/main/test-data/alias-reuse1.zsh new file mode 100644 index 0000000..1fd61a0 --- /dev/null +++ b/highlighters/main/test-data/alias-reuse1.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a | a' + +BUFFER='b | b' + +expected_region_highlight=( + '1 1 alias' # b + '3 3 commandseparator' # | + '5 5 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse2.zsh b/highlighters/main/test-data/alias-reuse2.zsh new file mode 100644 index 0000000..37251fb --- /dev/null +++ b/highlighters/main/test-data/alias-reuse2.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a && a' + +BUFFER='b && b' + +expected_region_highlight=( + '1 1 alias' # b + '3 4 commandseparator' # && + '6 6 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse3.zsh b/highlighters/main/test-data/alias-reuse3.zsh new file mode 100644 index 0000000..5d7150a --- /dev/null +++ b/highlighters/main/test-data/alias-reuse3.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a; a' + +BUFFER='b; b' + +expected_region_highlight=( + '1 1 alias' # b + '2 2 commandseparator' # ; + '4 4 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse4.zsh b/highlighters/main/test-data/alias-reuse4.zsh new file mode 100644 index 0000000..7ad7038 --- /dev/null +++ b/highlighters/main/test-data/alias-reuse4.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a $(a)' + +BUFFER='b $(b)' + +expected_region_highlight=( + '1 1 alias' # b + '3 6 default' # $(b) + '3 6 command-substitution-unquoted' # $(b) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 alias' # b + '6 6 command-substitution-delimiter-unquoted' # ) +) diff --git a/highlighters/main/test-data/alias-reuse5.zsh b/highlighters/main/test-data/alias-reuse5.zsh new file mode 100644 index 0000000..881401b --- /dev/null +++ b/highlighters/main/test-data/alias-reuse5.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a < <(a)' + +BUFFER='b < <(b)' + +expected_region_highlight=( + '1 1 alias' # b + '3 3 redirection' # < + '5 8 default' # <(b) + '5 8 process-substitution' # <(b) + '5 6 process-substitution-delimiter' # <( + '7 7 alias' # b + '8 8 process-substitution-delimiter' # ) +) From 1715f39a4680a27abd57fc30c98a95fdf191be45 Mon Sep 17 00:00:00 2001 From: Hussaina Begum Nandyala Date: Thu, 15 Oct 2020 09:39:04 +0530 Subject: [PATCH 38/84] docs: Add resource link for NetBSD operating system Signed-off-by: Hussaina Begum Nandyala --- INSTALL.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 0ca2295..48b724f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,6 +9,7 @@ How to install * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* NetBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][netbsd-port]) * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] @@ -23,8 +24,9 @@ How to install [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting +[netbsd-port]: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/shells/zsh-syntax-highlighting/ [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting -[openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ +[openbsd-port]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting From 046cb03a120ca3376f076d746009bf9b7f052969 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 28 Oct 2020 22:46:04 -0500 Subject: [PATCH 39/84] main: Convert in_alias to an array of shift counts No functional change. Keeps track of how deep we are in expanding nested aliases for the next commit. --- highlighters/main/main-highlighter.zsh | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2a29d0d..45835c3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -76,7 +76,7 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 - if (( in_alias )); then + if (( $#in_alias )); then [[ $1 == unknown-token ]] && alias_style=unknown-token return fi @@ -498,17 +498,18 @@ _zsh_highlight_main_highlighter__try_expand_parameter() _zsh_highlight_main_highlighter_highlight_list() { integer start_pos end_pos=0 buf_offset=$1 has_end=$3 - # alias_style is the style to apply to an alias once in_alias=0 + # alias_style is the style to apply to an alias once $#in_alias == 0 # Usually 'alias' but set to 'unknown-token' if any word expanded from # the alias would be highlighted as unknown-token # param_style is analogous for parameter expansions local alias_style param_style last_arg arg buf=$4 highlight_glob=true saw_assignment=false style local in_array_assignment=false # true between 'a=(' and the matching ')' - # in_alias is equal to the number of shifts needed until arg=args[1] pops an - # arg from BUFFER and not added by an alias. + # in_alias is an array of integers with each element equal to the number + # of shifts needed until arg=args[1] pops an arg from the next level up + # alias or from BUFFER. # in_param is analogous for parameter expansions - integer in_alias=0 in_param=0 len=$#buf - local -a match mbegin mend list_highlights + integer in_param=0 len=$#buf + local -a in_alias match mbegin mend list_highlights # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a local -A seen_alias # Pattern for parameter names @@ -596,9 +597,11 @@ _zsh_highlight_main_highlighter_highlight_list() last_arg=$arg arg=$args[1] shift args - if (( in_alias )); then - (( in_alias-- )) - if (( in_alias == 0 )); then + if (( $#in_alias )); then + (( in_alias[1]-- )) + # Remove leading 0 entries + in_alias=($in_alias[$in_alias[(i)<1->],-1]) + if (( $#in_alias == 0 )); then seen_alias=() # start_pos and end_pos are of the alias (previous $arg) here _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style @@ -637,7 +640,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi - if (( in_alias == 0 && in_param == 0 )); then + if (( $#in_alias == 0 && in_param == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. [[ "$proc_buf" = (#b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]] # The first, outer parenthesis @@ -693,7 +696,6 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $res == "alias" ]]; then # Mark insane aliases as unknown-token (cf. #263). if [[ $arg == ?*=* ]]; then - (( in_alias == 0 )) && in_alias=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi @@ -707,15 +709,15 @@ _zsh_highlight_main_highlighter_highlight_list() alias_args=(${(z)REPLY}) fi args=( $alias_args $args ) - if (( in_alias == 0 )); then + if (( $#in_alias == 0 )); then alias_style=alias - # Add one because we will in_alias-- on the next loop iteration so - # this iteration should be considered in in_alias as well - (( in_alias += $#alias_args + 1 )) else - # This arg is already included in the count, so no need to + 1. - (( in_alias += $#alias_args )) + # Transfer the count of this arg to the new element about to be appended. + (( in_alias[1]-- )) fi + # Add one because we will in_alias[1]-- on the next loop iteration so + # this iteration should be considered in in_alias as well + in_alias=( $(($#alias_args + 1)) $in_alias ) (( in_redirection++ )) # Stall this arg continue else @@ -854,7 +856,7 @@ _zsh_highlight_main_highlighter_highlight_list() style=commandseparator elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then style=commandseparator - elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then + elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( $#in_alias )); then style=commandseparator else # Empty commands (semicolon follows nothing) are valid syntax. @@ -1147,7 +1149,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style done - (( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style + (( $#in_alias )) && in_alias=() _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style (( in_param == 1 )) && in_param=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] REPLY=$(( end_pos + ${#match[1]} - 1 )) @@ -1258,7 +1260,7 @@ _zsh_highlight_main_highlighter_check_path() # If this word ends the buffer, check if it's the prefix of a valid path. if (( has_end && (len == end_pos) )) && - (( ! in_alias )) && + (( ! $#in_alias )) && [[ $WIDGET != zle-line-finish ]]; then # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local -a tmp From 75c0eb0717aa9e2f5668212155398867032df74e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 28 Oct 2020 23:09:40 -0500 Subject: [PATCH 40/84] main: Remember nest level an alias was seen in for seen_alias Fixes #775. --- highlighters/main/main-highlighter.zsh | 15 +++++++-- highlighters/main/test-data/alias-self2.zsh | 37 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/alias-self2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 45835c3..4ea3f34 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -601,6 +601,12 @@ _zsh_highlight_main_highlighter_highlight_list() (( in_alias[1]-- )) # Remove leading 0 entries in_alias=($in_alias[$in_alias[(i)<1->],-1]) + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + unset "seen_alias[$alias_name]" + done + } if (( $#in_alias == 0 )); then seen_alias=() # start_pos and end_pos are of the alias (previous $arg) here @@ -699,7 +705,7 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi - seen_alias[$arg]=1 + seen_alias[$arg]=$#in_alias _zsh_highlight_main__resolve_alias $arg local -a alias_args # Elision is desired in case alias x='' @@ -881,7 +887,12 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' highlight_glob=true saw_assignment=false - seen_alias=() + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + unset "seen_alias[$alias_name]" + done + } if [[ $arg != '|' && $arg != '|&' ]]; then next_word+=':start_of_pipeline:' fi diff --git a/highlighters/main/test-data/alias-self2.zsh b/highlighters/main/test-data/alias-self2.zsh new file mode 100644 index 0000000..fd6ae03 --- /dev/null +++ b/highlighters/main/test-data/alias-self2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias cat='cat | cat' + +BUFFER='cat' + +expected_region_highlight=( + '1 3 alias' # cat +) From 5eb494852ebb99cf5c2c2bffee6b74e6f1bf38d0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 23 Dec 2020 22:13:22 -0600 Subject: [PATCH 41/84] Switch to GitHub Actions from Travis --- .github/workflows/test.yml | 73 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 56 ----------------------------- README.md | 6 ++-- release.md | 2 +- 4 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8221926 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,73 @@ +--- +name: Tests +on: + push: + paths-ignore: + - '**.md' + - '**.png' + pull_request: + paths-ignore: + - '**.md' + - '**.png' + schedule: + - cron: '29 7 * * 1' + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - master + - 5.8 + - 5.7.1 + - 5.7 + - 5.6.2 + - 5.6.1 + - 5.6 + - 5.5.1 + - 5.5 + - 5.4.2 + - 5.4.1 + - 5.4 + - 5.3.1 + - 5.3 + - 5.2 + - 5.1.1 + - 5.1 + - 5.0.8 + - 5.0.7 + - 5.0.6 + - 5.0.5 + - 5.0.4 + - 5.0.3 + - 5.0.2 + - 5.0.1 + - 5.0.0 + - 4.3.17 + - 4.3.16 + - 4.3.15 + - 4.3.14 + - 4.3.13 + - 4.3.12 + - 4.3.11 + container: + image: zshusers/zsh:${{ matrix.version }} + steps: + - uses: actions/checkout@v2 + - run: install_packages bsdmainutils make procps + - run: make test + + notify: + runs-on: ubuntu-latest + needs: test + if: failure() && (github.repository_owner == 'zsh-users') + steps: + - + name: Notify IRC + uses: Gottox/irc-message-action@v1 + with: + channel: '#zsh-syntax-highlighting' + nickname: zsyh-gh-bot + message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4ee2765..0000000 --- a/.travis.yml +++ /dev/null @@ -1,56 +0,0 @@ -language: generic -sudo: required - -env: - - ZSH=master - - ZSH=5.8 - - ZSH=5.7.1 - - ZSH=5.7 - - ZSH=5.6.2 - - ZSH=5.6.1 - - ZSH=5.6 - - ZSH=5.5.1 - - ZSH=5.5 - - ZSH=5.4.2 - - ZSH=5.4.1 - - ZSH=5.4 - - ZSH=5.3.1 - - ZSH=5.3 - - ZSH=5.2 - - ZSH=5.1.1 - - ZSH=5.1 - - ZSH=5.0.8 - - ZSH=5.0.7 - - ZSH=5.0.6 - - ZSH=5.0.5 - - ZSH=5.0.4 - - ZSH=5.0.3 - - ZSH=5.0.2 - - ZSH=5.0.1 - - ZSH=5.0.0 - - ZSH=4.3.17 - - ZSH=4.3.16 - - ZSH=4.3.15 - - ZSH=4.3.14 - - ZSH=4.3.13 - - ZSH=4.3.12 - - ZSH=4.3.11 - -script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps bsdmainutils && make test' - -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/367e241cdea60cb2070b - on_success: change - on_failure: always - on_start: never - irc: - channels: - - "chat.freenode.net#zsh-syntax-highlighting" - on_success: change - on_failure: always - on_start: never - use_notice: true - template: - - "%{repository}/%{branch}#%{build_number}: %{message} Changes : %{compare_url} | Build : %{build_url}" diff --git a/README.md b/README.md index 303ee1e..36fbdd7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis] +zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] ======================= **[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].** @@ -93,5 +93,5 @@ Syntax highlighting is done by pluggable highlighter scripts. See the [documentation on highlighters](docs/highlighters.md) for details and configuration settings. -[build-status-image]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master -[build-status-travis]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting +[build-status]: https://github.com/zsh-users/zsh-syntax-highlighting/actions +[build-status-image]: https://github.com/zsh-users/zsh-syntax-highlighting/workflows/Tests/badge.svg diff --git a/release.md b/release.md index 8df4b9c..075f221 100644 --- a/release.md +++ b/release.md @@ -5,7 +5,7 @@ - Check open issues and outstanding pull requests - Confirm `make test` passes - check with multiple zsh versions - (easiest to check travis: https://travis-ci.org/zsh-users/zsh-syntax-highlighting/) + (easiest to check GitHub Actions: https://github.com/zsh-users/zsh-syntax-highlighting/actions) - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Make sure there are no local commits and that `git status` is clean; From 205bc7ea199cfd4cded51d465baad63b3d7f3aad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 1 Mar 2021 20:21:39 +0000 Subject: [PATCH 42/84] 'main': Disable a lint warning when env(1) was followed by a pipe. Fixes #797. --- highlighters/main/main-highlighter.zsh | 4 +- .../main/test-data/null-exec2-printenv.zsh | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/null-exec2-printenv.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4ea3f34..8f792e6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -916,8 +916,8 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' - if [[ $arg == 'exec' ]]; then - # To allow "exec 2>&1;" where there's no command word + if [[ $arg == 'exec' || $arg == 'env' ]]; then + # To allow "exec 2>&1;" and "env | grep" where there's no command word next_word+=':regular:' fi else diff --git a/highlighters/main/test-data/null-exec2-printenv.zsh b/highlighters/main/test-data/null-exec2-printenv.zsh new file mode 100644 index 0000000..59a2cef --- /dev/null +++ b/highlighters/main/test-data/null-exec2-printenv.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'env | grep $needle' + +expected_region_highlight=( + '1 3 precommand' # env + '5 5 commandseparator' # | + '7 10 command' # grep + '12 18 default' # $needle +) From e8517244f7d2ae4f9d979faf94608d6e4a74a73e Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Tue, 9 Feb 2021 15:34:36 +0100 Subject: [PATCH 43/84] main: Allow for "]" in shell aliases PR #776 fixed an issue with complex aliases and expansion. However, this change also introduced a problem with aliases which contain `]` (for example, commonly seen on macOS: `alias ]=open`), due to using an associative array `seen_alias`, indexed by the alias name. Due to `"$seen_alias[$arg]"`, it would fail when `$arg` is expanded to anything containing `]`'. Thus, typing `] /` would result in: ``` > ] / (anon):unset:3: seen_alias[]]: invalid parameter name ``` This change fixes the issue by ensuring we properly access keys in the associative array `seen_alias`. Older versions of zsh have issues with map keys having special characters, especially lacking ways to remove such keys. The issue is described in detail in https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element. This fix uses proposal from [zsh-workers/43269](https://www.zsh.org/mla/workers/2018/msg01073.html), discovered by Stephane Chazelas, that boils down to avoid removing keys from the map, and reconstruct the map anew with some keys omitted. Co-authored-by: @phy1729 --- highlighters/main/main-highlighter.zsh | 19 +++++---- .../main/test-data/alias-brackets.zsh | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 highlighters/main/test-data/alias-brackets.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8f792e6..9186157 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -601,16 +601,19 @@ _zsh_highlight_main_highlighter_highlight_list() (( in_alias[1]-- )) # Remove leading 0 entries in_alias=($in_alias[$in_alias[(i)<1->],-1]) - (){ - local alias_name - for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do - unset "seen_alias[$alias_name]" - done - } if (( $#in_alias == 0 )); then seen_alias=() # start_pos and end_pos are of the alias (previous $arg) here _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style + else + # We can't unset keys that contain special characters (] \ and some others). + # More details: https://www.zsh.org/workers/43269 + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}") + done + } fi fi if (( in_param )); then @@ -890,7 +893,9 @@ _zsh_highlight_main_highlighter_highlight_list() (){ local alias_name for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do - unset "seen_alias[$alias_name]" + # We can't unset keys that contain special characters (] \ and some others). + # More details: https://www.zsh.org/workers/43269 + seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}") done } if [[ $arg != '|' && $arg != '|&' ]]; then diff --git a/highlighters/main/test-data/alias-brackets.zsh b/highlighters/main/test-data/alias-brackets.zsh new file mode 100644 index 0000000..ede6c9a --- /dev/null +++ b/highlighters/main/test-data/alias-brackets.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# Have to use cat here as it must be a command that exists. +# Otherwise, the test would fail with the first token being recognized +# as an "unknown-token". +alias ]=cat + +BUFFER='] /' + +expected_region_highlight=( + '1 1 alias' # ] + '3 3 path' # / +) From 993a07fc7f4e077b556192cfc5c3efc29b40fd96 Mon Sep 17 00:00:00 2001 From: Robert <64484887+robert5800@users.noreply.github.com> Date: Sat, 10 Apr 2021 22:48:51 +0200 Subject: [PATCH 44/84] docs: Fix broken link to fish shell --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36fbdd7..4803ec7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] *Requirements: zsh 4.3.11+.* -[fish]: http://www.fishshell.com/ +[fish]: https://fishshell.com/ [zsh]: http://www.zsh.org/ This package provides syntax highlighting for the shell zsh. It enables From ebef4e55691f62e630318d56468e5798367aa81c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 14 Apr 2021 10:39:01 +0000 Subject: [PATCH 45/84] docs: Use SSL for the link to zsh's homepage. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4803ec7..482a648 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] *Requirements: zsh 4.3.11+.* [fish]: https://fishshell.com/ -[zsh]: http://www.zsh.org/ +[zsh]: https://www.zsh.org/ This package provides syntax highlighting for the shell zsh. It enables highlighting of commands whilst they are typed at a zsh prompt into an From 894127b221ab73847847bf7cf31eeb709bc16dc5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 20 May 2021 20:10:34 -0500 Subject: [PATCH 46/84] docs,CI: Switch to Libera.Chat --- .github/workflows/test.yml | 1 + HACKING.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8221926..df2b726 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,6 +68,7 @@ jobs: name: Notify IRC uses: Gottox/irc-message-action@v1 with: + server: irc.libera.chat channel: '#zsh-syntax-highlighting' nickname: zsyh-gh-bot message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' diff --git a/HACKING.md b/HACKING.md index 6fd195c..ddd39a4 100644 --- a/HACKING.md +++ b/HACKING.md @@ -95,5 +95,5 @@ zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-hi IRC channel ----------- -We're on #zsh-syntax-highlighting on freenode. +We're on #zsh-syntax-highlighting on Libera.Chat. From 0e1bb14452e3fc66dcc81531212e1061e02c1a61 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 29 May 2021 23:24:20 -0500 Subject: [PATCH 47/84] main: precommands += proxychains --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9186157..6f14f53 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -362,6 +362,7 @@ _zsh_highlight_highlighter_main_paint() 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 + 'proxychains' q:f # proxychains 4.4.0 # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k From f0e6a8ef5c90ff3e1e9516df666e36e02d0f362d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 28 Jun 2021 23:02:31 -0500 Subject: [PATCH 48/84] main: Honor shwordsplit when expanding parameters Closes #687, #818. --- highlighters/main/main-highlighter.zsh | 6 ++- .../main/test-data/opt-shwordsplit1.zsh | 2 +- .../parameter-expansion-shwordsplit.zsh | 38 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/parameter-expansion-shwordsplit.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6f14f53..b251a3c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -477,7 +477,11 @@ _zsh_highlight_main_highlighter__try_expand_parameter() ;; (*) # scalar, presumably - words=( ${(P)MATCH} ) + if [[ $zsyh_user_options[shwordsplit] == on ]]; then + words=( ${(P)=MATCH} ) + else + words=( ${(P)MATCH} ) + fi ;; esac reply=( "${words[@]}" ) diff --git a/highlighters/main/test-data/opt-shwordsplit1.zsh b/highlighters/main/test-data/opt-shwordsplit1.zsh index 7455785..4a7689b 100644 --- a/highlighters/main/test-data/opt-shwordsplit1.zsh +++ b/highlighters/main/test-data/opt-shwordsplit1.zsh @@ -36,5 +36,5 @@ ed() { command ed "$@" } BUFFER=$'$EDITOR' expected_region_highlight=( - '1 7 function "issue #687"' # $EDITOR + '1 7 function' # $EDITOR ) diff --git a/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh b/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh new file mode 100644 index 0000000..0bf6f4c --- /dev/null +++ b/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +setopt sh_word_split +local foo='echo foo' + +BUFFER='$foo' + +expected_region_highlight=( + '1 4 builtin' # $foo +) From dffe304567c86f06bf1be0fce200077504e79783 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 3 Jul 2021 14:33:17 -0500 Subject: [PATCH 49/84] CI: Pull image from the GitHub container registry --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index df2b726..087a25e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: - 4.3.12 - 4.3.11 container: - image: zshusers/zsh:${{ matrix.version }} + image: ghcr.io/zsh-users/zsh:${{ matrix.version }} steps: - uses: actions/checkout@v2 - run: install_packages bsdmainutils make procps From 6e0e950154a4c6983d9e077ed052298ad9126144 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Fri, 20 Aug 2021 11:26:52 +0000 Subject: [PATCH 50/84] *: Fix spelling Part of PR #832. --- docs/highlighters.md | 2 +- highlighters/main/main-highlighter.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index bb72e54..17b9df4 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -25,7 +25,7 @@ By default, all command lines are highlighted. However, it is possible to prevent command lines longer than a fixed number of characters from being highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum length (in characters) of command lines to be highlighter. This is useful when -editing very long comand lines (for example, with the [`fned`][fned] utility +editing very long command lines (for example, with the [`fned`][fned] utility function). Example: [fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b251a3c..8881dfa 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -744,7 +744,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then if (( in_redirection == 1 )); then - # Two consecuive redirection operators is an error. + # Two consecutive redirection operators is an error. _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token else in_redirection=2 From f6a22fa842e0e6af00df2e9c21c8de6c4614d6fc Mon Sep 17 00:00:00 2001 From: Leonardo Gama Date: Tue, 21 Sep 2021 10:48:51 -0300 Subject: [PATCH 51/84] docs: Change highlighters' URL indexes from numbers to labels --- docs/highlighters.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 17b9df4..1b4992b 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -3,19 +3,19 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* `main` - the base highlighter, and the only one [active by default][1]. -* `brackets` - [matches brackets][2] and parenthesis. -* `pattern` - matches [user-defined patterns][3]. -* `cursor` - matches [the cursor position][4]. -* `root` - highlights the whole command line [if the current user is root][5]. -* `line` - applied to [the whole command line][6]. +* `main` - the base highlighter, and the only one [active by default][main]. +* `brackets` - [matches brackets][brackets] and parenthesis. +* `pattern` - matches [user-defined patterns][pattern]. +* `cursor` - matches [the cursor position][cursor]. +* `root` - highlights the whole command line [if the current user is root][root]. +* `line` - applied to [the whole command line][line]. -[1]: highlighters/main.md -[2]: highlighters/brackets.md -[3]: highlighters/pattern.md -[4]: highlighters/cursor.md -[5]: highlighters/root.md -[6]: highlighters/line.md +[main]: highlighters/main.md +[brackets]: highlighters/brackets.md +[pattern]: highlighters/pattern.md +[cursor]: highlighters/cursor.md +[root]: highlighters/root.md +[line]: highlighters/line.md Highlighter-independent settings From 1a9264bc661b3d52756916bf9ec3f41687d64db2 Mon Sep 17 00:00:00 2001 From: Leonardo Gama Date: Tue, 21 Sep 2021 10:52:48 -0300 Subject: [PATCH 52/84] docs: Add `regexp` to the list of built-in highlighters --- docs/highlighters.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/highlighters.md b/docs/highlighters.md index 1b4992b..544dffb 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -6,6 +6,7 @@ Syntax highlighting is done by pluggable highlighters: * `main` - the base highlighter, and the only one [active by default][main]. * `brackets` - [matches brackets][brackets] and parenthesis. * `pattern` - matches [user-defined patterns][pattern]. +* `regexp` - matches [user-defined regular expressions][regexp]. * `cursor` - matches [the cursor position][cursor]. * `root` - highlights the whole command line [if the current user is root][root]. * `line` - applied to [the whole command line][line]. @@ -13,6 +14,7 @@ Syntax highlighting is done by pluggable highlighters: [main]: highlighters/main.md [brackets]: highlighters/brackets.md [pattern]: highlighters/pattern.md +[regexp]: highlighters/regexp.md [cursor]: highlighters/cursor.md [root]: highlighters/root.md [line]: highlighters/line.md From c7caf57ca805abd54f11f756fda6395dd4187f8a Mon Sep 17 00:00:00 2001 From: Daniel Kuettel Date: Sat, 25 Sep 2021 11:21:23 +0200 Subject: [PATCH 53/84] check KEYS_QUEUED_COUNT and PENDING to skip parsing when pasting --- zsh-syntax-highlighting.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index d20dc5b..14f6e1f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -219,7 +219,8 @@ _zsh_highlight() [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret # Do not highlight if there are pending inputs (copy/paste). - [[ $PENDING -gt 0 ]] && return $ret + (( KEYS_QUEUED_COUNT > 0 )) && return $ret + (( PENDING > 0 )) && return $ret { local cache_place From b392045e6f37610a79c891db1529ae5f6ad752d7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 24 Jan 2022 07:57:33 +0000 Subject: [PATCH 54/84] driver: Simplify grammar of a comment. No functional change. --- zsh-syntax-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 14f6e1f..2b42910 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -73,8 +73,8 @@ _zsh_highlight__is_function_p() { # This function takes a single argument F and returns True iff F denotes the # name of a callable function. A function is callable if it is fully defined # or if it is marked for autoloading and autoloading it at the first call to it -# will succeed. In particular, if a function has been marked for autoloading -# but is not available in $fpath, then this function will return False therefor. +# will succeed. In particular, if F has been marked for autoloading +# but is not available in $fpath, then calling this function on F will return False. # # See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { From c10808ad5f3ace0696f900b9c543172bc1f8e27c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jan 2022 09:54:35 +0000 Subject: [PATCH 55/84] main: New test for issue #854 --- .../test-data/block-assignment-no-command.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/block-assignment-no-command.zsh diff --git a/highlighters/main/test-data/block-assignment-no-command.zsh b/highlighters/main/test-data/block-assignment-no-command.zsh new file mode 100644 index 0000000..ec52c98 --- /dev/null +++ b/highlighters/main/test-data/block-assignment-no-command.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2022 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'{ a=42 }' + +expected_region_highlight=( + '1 1 reserved-word' # { + '3 6 assign' # a=42 + '5 6 default' # 42 + '8 8 reserved word "issue #854"' # } +) From 0ddb1a8d51205d53ea283e9fdd5135eb4039fec8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Feb 2022 18:03:11 +0000 Subject: [PATCH 56/84] driver: Bump the in-development is-at-least checks so they return false on zsh 5.8.1, released yesterday. Fixes #856 Fixes #857 --- release.md | 1 + zsh-syntax-highlighting.zsh | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/release.md b/release.md index 075f221..f8565e8 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,6 @@ # Release procedure (for developers): +- Ensure every `is-at-least` invocation passes a stable zsh release's version number as the first argument - For minor (A.B.0) releases: - Check whether the release uses any not-yet-released zsh features - Check open issues and outstanding pull requests diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 2b42910..bec0189 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -158,12 +158,15 @@ _zsh_highlight() # # The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee. # The version number at the time was 5.8.0.2-dev (see Config/version.mk). - # Therefore, on 5.8.0.3 and newer the memo= feature is available. + # Therefore, on zsh master 5.8.0.3 and newer the memo= feature is available. + # However, there's also the zsh 5.8.1 release, which doesn't have the + # memo= feature. # - # On zsh version 5.8.0.2 between the aforementioned commit and the - # first Config/version.mk bump after it (which, at the time of writing, - # is yet to come), this condition will false negative. - if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then + # On zsh master 5.8.0.2 between the aforementioned commit and the + # first Config/version.mk bump after it (zsh-5.8-607-g75c1edde5, the + # bump to 5.8.1.1-dev following the backport to master of the bump + # to 5.8.1), this condition will false negative. + if is-at-least 5.8.1.1 $ZSH_VERSION.0.0; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -413,9 +416,8 @@ _zsh_highlight_call_widget() # as done by _zsh_highlight, can only be done from inside a widget # function — a catch-22. # -# See _zsh_highlight for the magic version number. (The use of 5.8.0.2 -# rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) -if is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget +# See _zsh_highlight for the magic version number. +if is-at-least 5.8.1.1 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From 56b44334617aa719e8e01bb5e00d3e176114a036 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Feb 2022 21:31:46 +0000 Subject: [PATCH 57/84] CI += zsh 5.8.1 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 087a25e..60818a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: matrix: version: - master + - 5.8.1 - 5.8 - 5.7.1 - 5.7 From caeca0bf6b4dd26026df884e32ca3915f0e1b780 Mon Sep 17 00:00:00 2001 From: Nuri Jung Date: Tue, 22 Feb 2022 10:32:37 +0000 Subject: [PATCH 58/84] docs: regexp: Document the platform dependency Patch by Nuri Jung; extension to cover PCRE by me. See #747. Fixes #747. --- docs/highlighters/regexp.md | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 5c8a89e..8f96826 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -12,11 +12,44 @@ To use this highlighter, associate regular expressions with styles in the ```zsh typeset -A ZSH_HIGHLIGHT_REGEXP -ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) +ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold) ``` -This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not -"sudoedit" +This will highlight lines that start with a call to the `rm` command. + +The regular expressions flavour used is [PCRE][pcresyntax] when the +`RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE), +as implemented by the platform's C library, otherwise. For details on the +latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the +`regcomp(3)` and `re_format(7)` manual pages on your system. + +For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`, +but not `sudoedit`, one might use: + +* When the `RE_MATCH_PCRE` is set: + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) + ``` + +* When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions): + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('\' fg=123,bold) + ``` + +* When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS): + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold) + ``` + +Note, however, that PCRE and POSIX ERE have a large common subset: +for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same +meaning in both flavours. The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` @@ -28,3 +61,5 @@ in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [perlretut]: http://perldoc.perl.org/perlretut.html [zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions +[MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module +[pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html From 643717ccafb35a1b56a1407c852275406467b6f0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 22 Feb 2022 10:38:45 +0000 Subject: [PATCH 59/84] changelog: Update zsh version numbers 5.8.0.3 was correct until 5.8.1 was released (see the great-grandparent of this commit, "driver: Bump the in-development is-at-least checks so they return false on zsh 5.8.1, released yesterday"). 5.2 -> 5.3 is simply a typo fix. zle-line-pre-redraw has been available since then. --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 9230236..d0a575a 100644 --- a/changelog.md +++ b/changelog.md @@ -7,9 +7,9 @@ The changes in this section were fixed by switching to a `zle-line-pre-redraw`-b implementation. Note: The new implementation will only be used on future zsh releases, -numbered 5.8.0.3 and newer, due to interoperability issues with other plugins +numbered 5.8.1.1 and newer, due to interoperability issues with other plugins (issues #418 and #579). The underlying zsh feature has been available since -zsh 5.2. +zsh 5.3. Whilst under development, the new implementation was known as the "feature/redrawhook" topic branch. From 2cd73fcbde1b47f0952027c0674c32b9f1756a59 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 22 Feb 2022 10:42:05 +0000 Subject: [PATCH 60/84] *: Update sourceforge links * changelog.md: Update links here too. They have not yet appeared in any stable release. Command used: perl -pi -e 's#http://zsh.sourceforge.net#https://zsh.sourceforge.io#g' **/*(.) --- README.md | 2 +- changelog.md | 6 +++--- docs/highlighters.md | 4 ++-- docs/highlighters/brackets.md | 2 +- docs/highlighters/cursor.md | 2 +- docs/highlighters/line.md | 2 +- docs/highlighters/main.md | 4 ++-- docs/highlighters/pattern.md | 2 +- docs/highlighters/regexp.md | 4 ++-- docs/highlighters/root.md | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 482a648..4768b3d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ enough information to allow computing the highlighting correctly.) See issues [#288][i288] and [#415][i415] for details. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 [i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415 diff --git a/changelog.md b/changelog.md index d0a575a..861fea5 100644 --- a/changelog.md +++ b/changelog.md @@ -89,8 +89,8 @@ to issue #418. (#90, part of #245 (feature/redrawhook)) -[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles -[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style +[zshcompsys-Standard-Styles]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#index-format_002c-completion-style @@ -289,7 +289,7 @@ This is a stable release, featuring bugfixes and minor improvements. - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. (79e4d3d12405, 15db71abd0cc, b56ee542d619; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting - Possible history expansions in double-quoted strings. (76ea9e1df316) diff --git a/docs/highlighters.md b/docs/highlighters.md index 544dffb..3a289ca 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -30,7 +30,7 @@ length (in characters) of command lines to be highlighter. This is useful when editing very long command lines (for example, with the [`fned`][fned] utility function). Example: -[fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed +[fned]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zed ```zsh ZSH_HIGHLIGHT_MAXLENGTH=512 @@ -61,7 +61,7 @@ same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting Some highlighters support additional configuration parameters; see each highlighter's documentation for details and examples. diff --git a/docs/highlighters/brackets.md b/docs/highlighters/brackets.md index 8410135..0101699 100644 --- a/docs/highlighters/brackets.md +++ b/docs/highlighters/brackets.md @@ -28,4 +28,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/cursor.md b/docs/highlighters/cursor.md index c4f22b8..3f87d42 100644 --- a/docs/highlighters/cursor.md +++ b/docs/highlighters/cursor.md @@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/line.md b/docs/highlighters/line.md index 1081fe1..f76639e 100644 --- a/docs/highlighters/line.md +++ b/docs/highlighters/line.md @@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index cc6186b..4a27653 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -116,6 +116,6 @@ of that (new) kind will be highlighted by the style `arg0_$kind`, where `$kind` is the output of `type -w` on the new kind of command word. If that style is not defined, then the style `arg0` will be used instead. -[zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines +[zshmisc-Simple-Commands-And-Pipelines]: https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index e67d79f..ecaa6a7 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -21,4 +21,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 8f96826..b1bed91 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -58,8 +58,8 @@ manual page][zshzle-Character-Highlighting]. See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [perlretut]: http://perldoc.perl.org/perlretut.html -[zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions +[zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions [MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module [pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html diff --git a/docs/highlighters/root.md b/docs/highlighters/root.md index d120d20..8197e4b 100644 --- a/docs/highlighters/root.md +++ b/docs/highlighters/root.md @@ -22,4 +22,4 @@ The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting From 5459ebcc4e788e1db514d95a0bf81adb6f19ea74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Feb 2022 18:19:58 +0000 Subject: [PATCH 61/84] main: precommand_options += grc --- highlighters/main/main-highlighter.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8881dfa..59e54ff 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -374,6 +374,9 @@ _zsh_highlight_highlighter_main_paint() 'chronic' :ev 'ifne' :n + # grc - a "generic colouriser" (that's their spelling, not mine) + 'grc' :se + ) # Commands that would need to skip one positional argument: # flock From c5ce0014677a0f69a10b676b6038ad127f40c6b1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Feb 2022 18:48:13 +0000 Subject: [PATCH 62/84] main: Deconfuse $EDITOR Work around . --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 59e54ff..ecdd0b8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -659,7 +659,7 @@ _zsh_highlight_main_highlighter_highlight_list() if (( $#in_alias == 0 && in_param == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - [[ "$proc_buf" = (#b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]] + [[ "$proc_buf" = (#b)(#s)(''([ $'\t']|[\\]$'\n')#)(?|)* ]] # The first, outer parenthesis integer offset="${#match[1]}" (( start_pos = end_pos + offset )) From caa749d030d22168445c4cb97befd406d2828db0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 14 May 2022 18:47:37 +0000 Subject: [PATCH 63/84] main: Housekeep $precommand_options. Add -v to tabbed(1). --- highlighters/main/main-highlighter.zsh | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ecdd0b8..0bd6dde 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -349,6 +349,7 @@ _zsh_highlight_highlighter_main_paint() 'noglob' '' # 'time' and 'nocorrect' shouldn't be added here; they're reserved words, not precommands. + # miscellaneous commands 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags @@ -363,24 +364,16 @@ _zsh_highlight_highlighter_main_paint() 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 'proxychains' q:f # proxychains 4.4.0 - - # As of OpenSSH 8.1p1 - 'ssh-agent' aEPt:csDd:k - # suckless-tools v44 - # Argumentless flags that can't be followed by a command: -v - 'tabbed' gnprtTuU:cdfhs - - # moreutils 0.62-1 - 'chronic' :ev - 'ifne' :n - - # grc - a "generic colouriser" (that's their spelling, not mine) - 'grc' :se - + 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 + 'tabbed' gnprtTuU:cdfhs:v # suckless-tools v44 + 'chronic' :ev # moreutils 0.62-1 + 'ifne' :n # moreutils 0.62-1 + 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) ) # Commands that would need to skip one positional argument: # flock # ssh + # _wanted (skip two) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false From b828f45da63fe57295ab6fafac240af6bd320f5c Mon Sep 17 00:00:00 2001 From: inventor500 Date: Fri, 23 Sep 2022 08:17:50 -0500 Subject: [PATCH 64/84] main precommands += torsocks --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0bd6dde..55fcdf3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -364,6 +364,8 @@ _zsh_highlight_highlighter_main_paint() 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 'proxychains' q:f # proxychains 4.4.0 + 'torsocks' idq:upaP # Torsocks 2.3.0 + 'torify' idq:upaP # Torsocks 2.3.0 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 'tabbed' gnprtTuU:cdfhs:v # suckless-tools v44 'chronic' :ev # moreutils 0.62-1 From 122dc464392302114556b53ec01a1390c54f739f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 23 Sep 2022 19:33:44 -0500 Subject: [PATCH 65/84] main: Add cpulimit to precommands Closes #897 --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 55fcdf3..7ec6249 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -371,6 +371,7 @@ _zsh_highlight_highlighter_main_paint() 'chronic' :ev # moreutils 0.62-1 'ifne' :n # moreutils 0.62-1 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) + 'cpulimit' elp:ivz # cpulimit 0.2 ) # Commands that would need to skip one positional argument: # flock From b2c910a85ed84cb7e5108e7cb3406a2e825a858f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Jun 2022 18:05:01 -0500 Subject: [PATCH 66/84] docs: Add Fig instructions Closes #877 --- INSTALL.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 48b724f..024dbd9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -75,6 +75,12 @@ This list is incomplete as there are too many Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in your `.zshrc`. +#### [Fig](https://fig.io) + +Click the `Install Plugin` button on the [Fig plugin page][fig-plugin]. + +[fig-plugin]: https://fig.io/plugins/other/zsh-syntax-highlighting + #### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) 1. Clone this repository in oh-my-zsh's plugins directory: From 75ba3d87e346de4fda7ce35c546ed8fa74d73a90 Mon Sep 17 00:00:00 2001 From: DiegoBoy Date: Tue, 31 Jan 2023 09:06:37 -0800 Subject: [PATCH 67/84] Fix proxychains args Args for proxychains should be f:q => -f file : -q quiet. From comments in the same function: # $precommand_options maps precommand name to values of $flags_with_argument, # $flags_sans_argument, and flags_solo for that precommand, joined by a # colon. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7ec6249..f691051 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -363,7 +363,7 @@ _zsh_highlight_highlighter_main_paint() 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 - 'proxychains' q:f # proxychains 4.4.0 + 'proxychains' f:q # proxychains 4.4.0 'torsocks' idq:upaP # Torsocks 2.3.0 'torify' idq:upaP # Torsocks 2.3.0 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 From 754cefe0181a7acd42fdcb357a67d0217291ac47 Mon Sep 17 00:00:00 2001 From: Johan van Eck <95653001+johanvaneck@users.noreply.github.com> Date: Fri, 3 Feb 2023 12:47:47 +0200 Subject: [PATCH 68/84] docs: Markup changes only (in the brew installation instructions) --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 024dbd9..89bf96c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,7 +8,7 @@ How to install * Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository]) * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] -* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* Mac OS X / Homebrew: `brew install zsh-syntax-highlighting` ([formula][brew-package]) * NetBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][netbsd-port]) * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] From 1386f1213eb0b0589d73cd3cf7c56e6a972a9bfd Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Sun, 21 May 2023 14:05:53 -0400 Subject: [PATCH 69/84] docs: ZSH_HIGHLIGHT_HIGHLIGHTERS is (main) by default --- docs/highlighters.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 3a289ca..fb64c3a 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -40,16 +40,14 @@ ZSH_HIGHLIGHT_MAXLENGTH=512 How to activate highlighters ---------------------------- -To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in -`~/.zshrc`, for example: +To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array. +By default `ZSH_HIGHLIGHT_HIGHLIGHTERS` is `(main)`. For example to activate +`brackets`, `pattern`, and `cursor` highlighters, in `~/.zshrc` do: ```zsh -ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) +ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets pattern cursor) ``` -By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main` -highlighter is active. - How to tweak highlighters ------------------------- From 143b25eb98aa3227af63bd7f04413e1b3e7888ec Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 5 Sep 2023 23:23:07 -0500 Subject: [PATCH 70/84] docs: Fix Homebrew link Closes #937. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 89bf96c..cce1411 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,7 +18,7 @@ How to install [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git -[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb +[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/z/zsh-syntax-highlighting.rb [debian-package]: https://packages.debian.org/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting From 65071902d306d543b2eecc6e954c6adaec9238a2 Mon Sep 17 00:00:00 2001 From: "Mario P. Cardenas" <15961362+Mario-paul@users.noreply.github.com> Date: Wed, 18 Aug 2021 01:26:20 -0400 Subject: [PATCH 71/84] docs: add instructions to source .zshrc file after package install --- INSTALL.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index cce1411..1c20468 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -3,6 +3,8 @@ How to install ### Using packages +First, install the package: + * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] * Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] (or in [OBS repository][obs-repository]) * Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository]) @@ -32,6 +34,36 @@ How to install See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) +Second, enable zsh-syntax-highlighting by sourcing the script. Running this command on the terminal will add the source line to the end of your .zshrc: + +* On most Linux distributions (except perhaps NixOS): + + ```zsh + echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +* NetBSD and OpenBSD: + + ```zsh + echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +* Mac OS X / Homebrew: + + ```zsh + echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +Then restart zsh (such as by opening a new instance of your terminal emulator). + + Alternatively, add the `source` command manually **at the end** of your `.zshrc`: + +* On most Linux distributions (except perhaps NixOS): +`source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +* NetBSD and OpenBSD: +`source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` + +Then restart zsh. ### In your ~/.zshrc From dd0cf649d13e9bfdb86d6bf2c3df0131a0ab5df3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 21:33:29 -0500 Subject: [PATCH 72/84] *: Use https in URLs --- INSTALL.md | 2 +- changelog.md | 2 +- docs/highlighters/regexp.md | 2 +- tests/README.md | 2 +- zsh-syntax-highlighting.zsh | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 1c20468..af92ac1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ First, install the package: [debian-package]: https://packages.debian.org/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting -[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ +[freebsd-port]: https://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting [netbsd-port]: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/shells/zsh-syntax-highlighting/ [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting diff --git a/changelog.md b/changelog.md index 861fea5..e56f259 100644 --- a/changelog.md +++ b/changelog.md @@ -735,7 +735,7 @@ in this area. ## Developer-visible changes: -- Test harness converted to [TAP](http://testanything.org/tap-specification.html) format +- Test harness converted to [TAP](https://testanything.org/tap-specification.html) format (d99aa58aaaef, et seq) - Run each test in a separate subprocess, isolating them from each other diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index b1bed91..8c711a3 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -59,7 +59,7 @@ See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting -[perlretut]: http://perldoc.perl.org/perlretut.html +[perlretut]: https://perldoc.perl.org/perlretut [zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions [MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module [pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html diff --git a/tests/README.md b/tests/README.md index cb3d943..eefeb54 100644 --- a/tests/README.md +++ b/tests/README.md @@ -104,7 +104,7 @@ By default, the results of all tests will be printed; to show only "interesting" results (tests that failed but were expected to succeed, or vice-versa), run `make quiet-test` (or `make test QUIET=y`). -[TAP]: http://testanything.org/ +[TAP]: https://testanything.org/ Performance test diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index bec0189..7827256 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -76,7 +76,7 @@ _zsh_highlight__is_function_p() { # will succeed. In particular, if F has been marked for autoloading # but is not available in $fpath, then calling this function on F will return False. # -# See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 +# See users/21671 https://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { if _zsh_highlight__is_function_p "$1" && ! _zsh_highlight__function_is_autoload_stub_p "$1" @@ -100,7 +100,7 @@ _zsh_highlight__function_callable_p() { # ------------------------------------------------------------------------------------------------- # Use workaround for bug in ZSH? -# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html +# zsh-users/zsh@48cadf4 https://www.zsh.org/mla/workers/2017/msg00034.html autoload -Uz is-at-least if is-at-least 5.4; then typeset -g zsh_highlight__pat_static_bug=false From 1e82d8c83efa8b9fd0c7d1b9baffeb47d6cff960 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 22:11:43 -0500 Subject: [PATCH 73/84] changelog: Update through HEAD --- changelog.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/changelog.md b/changelog.md index e56f259..ee124d3 100644 --- a/changelog.md +++ b/changelog.md @@ -56,6 +56,28 @@ Whilst under development, the new implementation was known as the - Add issue #712 to the previous release's changelog (hereinafter). +- Fix highlighting when using an alias twice inside another alias + [#769, #775] + +- Remove lint warning for `env` followed by a pipe + [#797] + +- Recognize `proxychains` as a precommand + [#814, #914] + +- Honor shwordsplit when expanding parameters + [#687, #818] + +- Skip highlighting when keys are still pending in more cases + [#835] + +- Recognize `grc` as a precommand + +- Recognize `torsocks` and `torift` as precommands + [#898] + +- Recognize `cpulimit` as a precommand + [#897] # Changes in 0.8.0-alpha1-pre-redrawhook @@ -168,6 +190,8 @@ to issue #418. - Recognize `env` as a precommand (e.g., `env FOO=bar ls`) +- Recognize `ionice` as a precommand + - Recognize `strace` as a precommand - Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set: From f8cd0b55b3d134cbc71360c94737528bca1a526f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 22:33:02 -0500 Subject: [PATCH 74/84] docs: Replace zplug instructions with zinit Fixes #883. --- INSTALL.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index af92ac1..2e1286d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -140,15 +140,15 @@ Zsh-syntax-highlighting is included with Prezto. See the Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`. +#### [zinit](https://github.com/zdharma-continuum/zinit) + +Add `zinit light zsh-users/zsh-syntax-highlighting` to the end of your +`.zshrc`. + #### [zplug](https://github.com/zplug/zplug) Add `zplug "zsh-users/zsh-syntax-highlighting", defer:2` to your `.zshrc`. -#### [zplugin](https://github.com/psprint/zplugin) - -Add `zplugin load zsh-users/zsh-syntax-highlighting` to the end of your -`.zshrc`. - ### System-wide installation From 0b5b3dcc0c603c9e1b3ad9d59b3d923a4b2d2437 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 11 Aug 2020 22:05:17 +0200 Subject: [PATCH 75/84] tests: parameter-to-global-alias: Use alias name less likely to clash --- highlighters/main/test-data/parameter-to-global-alias.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh index cd2283b..63f95da 100644 --- a/highlighters/main/test-data/parameter-to-global-alias.zsh +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -28,12 +28,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -if type x >/dev/null; then - skip_test="Test is written on the assumption that 'x' is not a valid command name, but that assumption does not hold" +if type global_alias >/dev/null; then + skip_test="Test is written on the assumption that 'global_alias' is not a valid command name, but that assumption does not hold" return 0 fi -alias -g x=y -local s=x +alias -g global_alias=y +local s=global_alias BUFFER=$'$s' From e82e2d042d55391e5c136c92ead4714db2d60b1a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 12:50:08 -0500 Subject: [PATCH 76/84] main: precommand_options += ktrace --- changelog.md | 3 +++ highlighters/main/main-highlighter.zsh | 1 + 2 files changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index ee124d3..851a918 100644 --- a/changelog.md +++ b/changelog.md @@ -79,6 +79,9 @@ Whilst under development, the new implementation was known as the - Recognize `cpulimit` as a precommand [#897] +- Recognize `ktrace` as a precommand + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f691051..54938b7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -372,6 +372,7 @@ _zsh_highlight_highlighter_main_paint() 'ifne' :n # moreutils 0.62-1 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) 'cpulimit' elp:ivz # cpulimit 0.2 + 'ktrace' fgpt:aBCcdiT ) # Commands that would need to skip one positional argument: # flock From d59ce0fbd014bd69b1eed21c029c0d51bf8d6a09 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 12:53:19 -0500 Subject: [PATCH 77/84] driver: Be resilient to KSH_ARRAYS being set in the calling scope --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 7827256..9f8fe48 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -123,7 +123,7 @@ _zsh_highlight() typeset -r ret # $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array. - (( ${+region_highlight} )) || { + (( ${+region_highlight[@]} )) || { echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined' echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)' return $ret From 71bd576af836517bda6dd574ef81176339144568 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 13:13:49 -0500 Subject: [PATCH 78/84] CI += zsh 5.9 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60818a6..76a7484 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: matrix: version: - master + - 5.9 - 5.8.1 - 5.8 - 5.7.1 From bb27265aeeb0a22fb77f1275118a5edba260ec47 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 13:25:08 -0500 Subject: [PATCH 79/84] CI: Update action versions --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76a7484..cd50b8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,7 +57,7 @@ jobs: container: image: ghcr.io/zsh-users/zsh:${{ matrix.version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: install_packages bsdmainutils make procps - run: make test @@ -68,9 +68,8 @@ jobs: steps: - name: Notify IRC - uses: Gottox/irc-message-action@v1 + uses: Gottox/irc-message-action@v2 with: - server: irc.libera.chat channel: '#zsh-syntax-highlighting' nickname: zsyh-gh-bot message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' From 9bb3db7fd2715e07804b23a78e0eed797e137610 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:02:40 -0600 Subject: [PATCH 80/84] driver: Use stable zsh release in is-at-least calls --- zsh-syntax-highlighting.zsh | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 9f8fe48..4295c93 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -155,18 +155,7 @@ _zsh_highlight() # C structs, so that none of the previous case patterns will match. # # In either case, fall back to a version check. - # - # The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee. - # The version number at the time was 5.8.0.2-dev (see Config/version.mk). - # Therefore, on zsh master 5.8.0.3 and newer the memo= feature is available. - # However, there's also the zsh 5.8.1 release, which doesn't have the - # memo= feature. - # - # On zsh master 5.8.0.2 between the aforementioned commit and the - # first Config/version.mk bump after it (zsh-5.8-607-g75c1edde5, the - # bump to 5.8.1.1-dev following the backport to master of the bump - # to 5.8.1), this condition will false negative. - if is-at-least 5.8.1.1 $ZSH_VERSION.0.0; then + if is-at-least 5.9; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -415,9 +404,7 @@ _zsh_highlight_call_widget() # We check this with a plain version number check, since a functional check, # as done by _zsh_highlight, can only be done from inside a widget # function — a catch-22. -# -# See _zsh_highlight for the magic version number. -if is-at-least 5.8.1.1 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget +if is-at-least 5.9 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From db085e4661f6aafd24e5acb5b2e17e4dd5dddf3e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:05:43 -0600 Subject: [PATCH 81/84] Tag version 0.8.0. --- .version | 2 +- changelog.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.version b/.version index 9fb1210..a3df0a6 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0-alpha2-dev +0.8.0 diff --git a/changelog.md b/changelog.md index 851a918..bc6614d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,6 @@ -# Changes in HEAD +# Changes in 0.8.0 + +This is a stable bugfix and feature release. Major new features and changes include: ## Changes fixed as part of the switch to zle-line-pre-redraw From dcc99a86497491dfe41fb8b0d5f506033546a8c0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:07:39 -0600 Subject: [PATCH 82/84] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index a3df0a6..d182dc9 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0 +0.8.1-dev From e0165eaa730dd0fa321a6a6de74f092fe87630b0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 6 Jan 2024 12:33:41 -0600 Subject: [PATCH 83/84] main: Refactor __is_redirection Fixes #942. --- changelog.md | 7 ++ highlighters/main/main-highlighter.zsh | 7 +- .../main/test-data/redirection-all.zsh | 95 +++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 highlighters/main/test-data/redirection-all.zsh diff --git a/changelog.md b/changelog.md index bc6614d..8ee5088 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +# Changes in HEAD + + +- Highlight `&>` `>&|` `>&!` `&>|` and `&>!` as redirection. + [#942] + + # Changes in 0.8.0 This is a stable bugfix and feature release. Major new features and changes include: diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 54938b7..3ec96d9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -254,10 +254,9 @@ _zsh_highlight_main__is_runnable() { _zsh_highlight_main__is_redirection() { # A redirection operator token: # - starts with an optional single-digit number; - # - then, has a '<' or '>' character; - # - is not a process substitution [<(...) or >(...)]. - # - is not a numeric glob <-> - [[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]] + # - is one of the tokens listed in zshmisc(1) + # - however (z) normalizes ! to | + [[ ${1#[0-9]} == (\<|\<\>|(\>|\>\>)(|\|)|\<\<(|-)|\<\<\<|\<\&|\&\<|(\>|\>\>)\&(|\|)|\&(\>|\>\>)(|\||\!)) ]] } # Resolve alias. diff --git a/highlighters/main/test-data/redirection-all.zsh b/highlighters/main/test-data/redirection-all.zsh new file mode 100644 index 0000000..e8ffb5d --- /dev/null +++ b/highlighters/main/test-data/redirection-all.zsh @@ -0,0 +1,95 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2024 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': foo 9<>foo >foo 9>foo >|foo >\!foo >>foo >>|foo >>\!foo <<&9 <&- >&- <&p >&p >&foo &>foo >&|foo >&\!foo &>|foo &>\!foo >>&foo &>>foo >>&|foo >>&\!foo &>>|foo &>>\!foo' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 redirection' # < + '4 6 default' # foo + '8 9 redirection' # 9< + '10 12 default' # foo + '14 15 redirection' # <> + '16 18 default' # foo + '20 22 redirection' # 9<> + '23 25 default' # foo + '27 27 redirection' # > + '28 30 default' # foo + '32 33 redirection' # 9> + '34 36 default' # foo + '38 39 redirection' # >| + '40 42 default' # foo + '44 45 redirection' # >\! + '46 48 default' # foo + '50 51 redirection' # >> + '52 54 default' # foo + '56 58 redirection' # >>| + '59 61 default' # foo + '63 65 redirection' # >>\! + '66 68 default' # foo + '70 72 redirection' # <<< + '73 75 default' # foo + '77 78 redirection' # <& + '79 79 numeric-fd' # 9 + '81 82 redirection' # >& + '83 83 numeric-fd' # 9 + '85 86 redirection' # <& + '87 87 redirection' # - + '89 90 redirection' # >& + '91 91 redirection' # - + '93 94 redirection' # <& + '95 95 redirection' # p + '97 98 redirection' # >& + '99 99 redirection' # p + '101 102 redirection' # >& + '103 105 default' # foo + '107 108 redirection' # &> + '109 111 default' # foo + '113 115 redirection' # >&| + '116 118 default' # foo + '120 122 redirection' # >&\! + '123 125 default' # foo + '127 129 redirection' # &>| + '130 132 default' # foo + '134 136 redirection' # &>\! + '137 139 default' # foo + '141 143 redirection' # >>& + '144 146 default' # foo + '148 150 redirection' # &>> + '151 153 default' # foo + '155 158 redirection' # >>&| + '159 161 default' # foo + '163 166 redirection' # >>&\! + '167 169 default' # foo + '171 174 redirection' # &>>| + '175 177 default' # foo + '179 182 redirection' # &>>\! + '183 185 default' # foo +) From 5eb677bb0fa9a3e60f0eff031dc13926e093df92 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 21 Nov 2024 14:56:08 +0000 Subject: [PATCH 84/84] 'main' tests: Don't assume ps(1) is available. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's actually unavailable in the minimal chroots Debian builds our package on. That's allowed by POSIX, which specifies ps(1) to be optional, whereas id(1) — - is not optional in POSIX - should exist on every system anyone might run the testsuite on - has the same length name, so test expectations don't have to be updated - doesn't take a filename argument (ditto) That does make the pipeline as a whole somewhat nonsensical semantically, but it remains just as valid syntactically. --- highlighters/main/test-data/multiple-redirections.zsh | 2 +- highlighters/main/test-data/simple-redirection.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index 778e712..1545c1b 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ps aux | grep java | sort | uniq | tail | head' +BUFFER='id bob | grep java | sort | uniq | tail | head' expected_region_highlight=( "1 2 command" # ps diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index e8c25e5..fb06f19 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ps aux | grep java' +BUFFER='id bob | grep java' expected_region_highlight=( "1 2 command" # ps