Skip to content

Commit 876c780

Browse files
committed
fix: export COMPLETE and _COMPLETE_INDEX env vars in bash/zsh completion hooks
The bash and zsh registration scripts set COMPLETE and _COMPLETE_INDEX as shell variables inside $(...) subshells, but never export them. This means the CLI binary does not see them in process.env, falls through to normal arg parsing, and errors on the -- separator. Fish and nushell are unaffected because they use inline prefix syntax (COMPLETE=fish cmd ...) which always exports to the child. Signed-off-by: LeTamanoir <martin.saldinger@kiln.fi>
1 parent 04c87be commit 876c780

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Completions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('register', () => {
231231
test('bash: generates complete -F script with nospace support', () => {
232232
const script = Completions.register('bash', 'mycli')
233233
expect(script).toContain('_incur_complete_mycli()')
234-
expect(script).toContain('COMPLETE="bash"')
234+
expect(script).toContain('export COMPLETE="bash"')
235235
expect(script).toContain('complete -o default -o bashdefault -o nosort -F')
236236
expect(script).toContain('"mycli" -- "${COMP_WORDS[@]}"')
237237
expect(script).toContain('compopt -o nospace')
@@ -240,7 +240,7 @@ describe('register', () => {
240240
test('zsh: generates compdef script', () => {
241241
const script = Completions.register('zsh', 'mycli')
242242
expect(script).toContain('#compdef mycli')
243-
expect(script).toContain('COMPLETE="zsh"')
243+
expect(script).toContain('export COMPLETE="zsh"')
244244
expect(script).toContain('compdef _incur_complete_mycli mycli')
245245
expect(script).toContain('_describe')
246246
})

src/Completions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ function bashRegister(name: string): string {
232232
local _COMPLETE_INDEX=\${COMP_CWORD}
233233
local _completions
234234
_completions=( $(
235-
COMPLETE="bash"
236-
_COMPLETE_INDEX="$_COMPLETE_INDEX"
235+
export COMPLETE="bash"
236+
export _COMPLETE_INDEX="$_COMPLETE_INDEX"
237237
"${name}" -- "\${COMP_WORDS[@]}"
238238
) )
239239
if [[ $? != 0 ]]; then
@@ -262,8 +262,8 @@ function zshRegister(name: string): string {
262262
return `#compdef ${name}
263263
_incur_complete_${id}() {
264264
local completions=("\${(@f)$(
265-
_COMPLETE_INDEX=$(( CURRENT - 1 ))
266-
COMPLETE="zsh"
265+
export _COMPLETE_INDEX=$(( CURRENT - 1 ))
266+
export COMPLETE="zsh"
267267
"${name}" -- "\${words[@]}" 2>/dev/null
268268
)}")
269269
if [[ -n $completions ]]; then

0 commit comments

Comments
 (0)