diff --git a/.github/dependencies.yml b/.github/dependencies.yml index 7794e3346..4a3c89eb7 100644 --- a/.github/dependencies.yml +++ b/.github/dependencies.yml @@ -46,7 +46,7 @@ dependencies: plugins/z: branch: master repo: agkozak/zsh-z - version: ae10ba3f4674c24ac353fd34deb2fd9f7b061055 + version: 519e5796df3db6c68317c7a3901444fab3241bbc precopy: | set -e test -e README.md && mv -f README.md MANUAL.md diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md index 9984d3b1f..790d4d389 100644 --- a/plugins/z/MANUAL.md +++ b/plugins/z/MANUAL.md @@ -33,6 +33,9 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d
Here are the latest features and updates. +- April 27, 2026 + + Fixes a bug where re-sourcing the script caused an infinite loop when Tab was pressed. Props to @maheshpec for [successfully diagnosing the problem](https://github.com/ohmyzsh/ohmyzsh/pull/13715). + + Fixes a bug where the completion widget was not identifying flags correctly. - March 31, 2026 + When the user hits Tab after entering a command-line argument that uses spaces as wildcards (e.g., `z us lo bi`), the command line is clear of detritus (i.e., it looks like `z /usr/local/bin` instead of `z us lo /usr/local/bin`). + Improved test for Docker containers. diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh index 456802d3d..e1a9bd076 100644 --- a/plugins/z/z.plugin.zsh +++ b/plugins/z/z.plugin.zsh @@ -960,8 +960,13 @@ add-zsh-hook chpwd _zshz_chpwd (( ${fpath[(ie)${0:A:h}]} <= ${#fpath} )) || fpath=( "${0:A:h}" "${fpath[@]}" ) -# Save the existing Tab binding -ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }" + +# Save the existing Tab binding so that the completion widget can invoke it, +# but being careful not to create a situation where the widget ends up calling +# itself and causing infinite recursion if this script is re-sourced. +if (( ! ${+widgets[_zshz_zle_completion_widget]} )); then + ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }" +fi ############################################################ # ZLE widget to fix spaces-as-wildcards completion @@ -976,7 +981,9 @@ ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }" # ZSHZ_CMD ############################################################ _zshz_zle_completion_widget() { - emulate -L zsh + + setopt LOCAL_OPTIONS EXTENDED_GLOB NO_KSH_ARRAYS NO_SH_WORD_SPLIT + local cmd=${ZSHZ_CMD:-${_Z_CMD:-z}} # If a trailing space was added after an already-completed absolute path @@ -994,7 +1001,7 @@ _zshz_zle_completion_widget() { parts=( ${(z)after} ) for p in $parts; do - if (( ! past_flags )) && [[ $p == -[cehlrRtx]## ]]; then + if (( ! past_flags )) && [[ $p == (-[cehlrRtx]##|--add|--complete|--help) ]]; then flag_parts+=( $p ) else past_flags=1 @@ -1012,9 +1019,12 @@ _zshz_zle_completion_widget() { zle ${ZSHZ[TAB_BINDING]:-expand-or-complete} } -zle -N _zshz_zle_completion_widget - -bindkey -M main '^I' _zshz_zle_completion_widget +# Register the widget and bind to Tab, but only if this script has not already +# been sourced -- avoid infinite recursion. +if (( ! ${+widgets[_zshz_zle_completion_widget]} )); then + zle -N _zshz_zle_completion_widget + bindkey -M main '^I' _zshz_zle_completion_widget +fi ############################################################ # zsh-z functions