Skip to content

Commit a3c6230

Browse files
authored
Merge pull request #6000 from mernen/fix-zsh-dynamic-completion
zsh: fix passing arguments in dynamic completion
2 parents 951536e + a4fb210 commit a3c6230

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

clap_complete/src/env/shells.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function _clap_dynamic_completer_NAME() {
370370
_CLAP_IFS="$_CLAP_IFS" \
371371
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
372372
VAR="zsh" \
373-
COMPLETER -- ${words} 2>/dev/null \
373+
COMPLETER -- "${words[@]}" 2>/dev/null \
374374
)}")
375375
376376
if [[ -n $completions ]]; then

clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function _clap_dynamic_completer_exhaustive() {
77
_CLAP_IFS="$_CLAP_IFS" \
88
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
99
COMPLETE="zsh" \
10-
exhaustive -- ${words} 2>/dev/null \
10+
exhaustive -- "${words[@]}" 2>/dev/null \
1111
)}")
1212

1313
if [[ -n $completions ]]; then

clap_complete/tests/testsuite/zsh.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,33 @@ fn complete_dynamic_empty_option_value() {
328328
let actual = runtime.complete(input, &term).unwrap();
329329
assert_data_eq!(actual, expected);
330330
}
331+
332+
#[test]
333+
#[cfg(all(unix, feature = "unstable-dynamic"))]
334+
#[cfg(feature = "unstable-shell-tests")]
335+
fn complete_dynamic_empty_space() {
336+
if !common::has_command(CMD) {
337+
return;
338+
}
339+
340+
let term = completest::Term::new();
341+
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
342+
343+
// Press left arrow twice to place cursor between the two spaces
344+
let input = "exhaustive quote -\x1b[D\x1b[D\t\t";
345+
let expected = snapbox::str![[r#"
346+
% exhaustive quote -
347+
--help -- Print help (see more with '--help')
348+
cmd-backslash --backslash -- Avoid '/n'
349+
cmd-backticks --backticks -- For more information see `echo test`
350+
cmd-brackets --brackets -- List packages [filter]
351+
cmd-double-quotes --double-quotes -- Can be "always", "auto", or "never"
352+
cmd-expansions --expansions -- Execute the shell command with $SHELL
353+
cmd-single-quotes --single-quotes -- Can be 'always', 'auto', or 'never'
354+
escape-help -- /tab/t"'
355+
help -- Print this message or the help of the given subcommand(s)
356+
--choice
357+
"#]];
358+
let actual = runtime.complete(input, &term).unwrap();
359+
assert_data_eq!(actual, expected);
360+
}

0 commit comments

Comments
 (0)