Diff
1diff --git a/.github/dependencies.yml b/.github/dependencies.yml
2index 7794e3346a69ca56a1b0ff56f9739d2674d9ab4f..4a3c89eb71ef262f113b936a39d3eca0a4c1e6b1 100644
3--- a/.github/dependencies.yml
4+++ b/.github/dependencies.yml
5@@ -46,7 +46,7 @@ dependencies:
6 plugins/z:
7 branch: master
8 repo: agkozak/zsh-z
9- version: ae10ba3f4674c24ac353fd34deb2fd9f7b061055
10+ version: 519e5796df3db6c68317c7a3901444fab3241bbc
11 precopy: |
12 set -e
13 test -e README.md && mv -f README.md MANUAL.md
14diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md
15index 9984d3b1f3d7b6deebb2491db153546cf95d550c..790d4d389289604c5d7ce23bcfef2abf682cd424 100644
16--- a/plugins/z/MANUAL.md
17+++ b/plugins/z/MANUAL.md
18@@ -33,6 +33,9 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d
19 <details>
20 <summary>Here are the latest features and updates.</summary>
21
22+- April 27, 2026
23+ + 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).
24+ + Fixes a bug where the completion widget was not identifying flags correctly.
25 - March 31, 2026
26 + 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`).
27 + Improved test for Docker containers.
28diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh
29index 456802d3d373b21805158cb274fe77325636db56..e1a9bd076e90ee23e50a17cf8fb47faf17ddac0f 100644
30--- a/plugins/z/z.plugin.zsh
31+++ b/plugins/z/z.plugin.zsh
32@@ -960,8 +960,13 @@ add-zsh-hook chpwd _zshz_chpwd
33
34 (( ${fpath[(ie)${0:A:h}]} <= ${#fpath} )) || fpath=( "${0:A:h}" "${fpath[@]}" )
35
36-# Save the existing Tab binding
37-ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }"
38+
39+# Save the existing Tab binding so that the completion widget can invoke it,
40+# but being careful not to create a situation where the widget ends up calling
41+# itself and causing infinite recursion if this script is re-sourced.
42+if (( ! ${+widgets[_zshz_zle_completion_widget]} )); then
43+ ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }"
44+fi
45
46 ############################################################
47 # ZLE widget to fix spaces-as-wildcards completion
48@@ -976,7 +981,9 @@ ZSHZ[TAB_BINDING]="${$(bindkey -M main '^I')##* }"
49 # ZSHZ_CMD
50 ############################################################
51 _zshz_zle_completion_widget() {
52- emulate -L zsh
53+
54+ setopt LOCAL_OPTIONS EXTENDED_GLOB NO_KSH_ARRAYS NO_SH_WORD_SPLIT
55+
56 local cmd=${ZSHZ_CMD:-${_Z_CMD:-z}}
57
58 # If a trailing space was added after an already-completed absolute path
59@@ -994,7 +1001,7 @@ _zshz_zle_completion_widget() {
60
61 parts=( ${(z)after} )
62 for p in $parts; do
63- if (( ! past_flags )) && [[ $p == -[cehlrRtx]## ]]; then
64+ if (( ! past_flags )) && [[ $p == (-[cehlrRtx]##|--add|--complete|--help) ]]; then
65 flag_parts+=( $p )
66 else
67 past_flags=1
68@@ -1012,9 +1019,12 @@ _zshz_zle_completion_widget() {
69 zle ${ZSHZ[TAB_BINDING]:-expand-or-complete}
70 }
71
72-zle -N _zshz_zle_completion_widget
73-
74-bindkey -M main '^I' _zshz_zle_completion_widget
75+# Register the widget and bind to Tab, but only if this script has not already
76+# been sourced -- avoid infinite recursion.
77+if (( ! ${+widgets[_zshz_zle_completion_widget]} )); then
78+ zle -N _zshz_zle_completion_widget
79+ bindkey -M main '^I' _zshz_zle_completion_widget
80+fi
81
82 ############################################################
83 # zsh-z functions