@@ -21,12 +21,24 @@ _${name}() {
2121 local shellCompDirectiveFilterDirs=${ ShellCompDirective . ShellCompDirectiveFilterDirs }
2222 local shellCompDirectiveKeepOrder=${ ShellCompDirective . ShellCompDirectiveKeepOrder }
2323
24- local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
24+ local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder isNewWord
2525 local -a completions
2626
2727 __${ name } _debug "\\n========= starting completion logic =========="
2828 __${ name } _debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
2929
30+ # Track whether the cursor is positioned on a new (empty) word so we can
31+ # pass an empty argument to the CLI when the user has already completed
32+ # the previous token (e.g. after typing a space).
33+ isNewWord=0
34+ if [ \${#words[@]} -ge \${CURRENT} ] && [ -z "\${words[\${CURRENT}]}" ]; then
35+ isNewWord=1
36+ __${ name } _debug "Detected empty current word via words[\${CURRENT}]"
37+ elif [ -n "\${BUFFER}" ] && [ "\${BUFFER[-1]}" = " " ]; then
38+ isNewWord=1
39+ __${ name } _debug "Detected trailing space in buffer"
40+ fi
41+
3042 # The user could have moved the cursor backwards on the command-line.
3143 # We need to trigger completion from the $CURRENT location, so we need
3244 # to truncate the command-line ($words) up to the $CURRENT location.
@@ -48,7 +60,7 @@ _${name}() {
4860
4961 # Prepare the command to obtain completions, ensuring arguments are quoted for eval
5062 local -a args_to_quote=("\${(@)words[2,-1]}")
51- if [ "\${lastChar}" = "" ]; then
63+ if [ "\${lastChar}" = "" ] || [ $isNewWord -eq 1 ] ; then
5264 # If the last parameter is complete (there is a space following it)
5365 # We add an extra empty parameter so we can indicate this to the go completion code.
5466 __${ name } _debug "Adding extra empty parameter"
0 commit comments