Skip to content

Commit 54947a1

Browse files
authored
Merge pull request #5981 from mernen/fix-bash-clap-complete-space
fix(complete): restore `nospace` in bash when reply ends in `=/:`
2 parents f88be57 + fd3f6d2 commit 54947a1

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

clap_complete/src/env/shells.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ _clap_complete_NAME() {
4141
_CLAP_IFS="$IFS" \
4242
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
4343
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
44+
_CLAP_COMPLETE_SPACE="$_CLAP_COMPLETE_SPACE" \
4445
VAR="bash" \
4546
"COMPLETER" -- "${COMP_WORDS[@]}" \
4647
) )
4748
if [[ $? != 0 ]]; then
4849
unset COMPREPLY
49-
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
50+
elif [[ $_CLAP_COMPLETE_SPACE == false ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
5051
compopt -o nospace
5152
fi
5253
}

clap_complete/tests/snapshots/home/dynamic-env/exhaustive/bash/.bashrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ _clap_complete_exhaustive() {
1414
_CLAP_IFS="$IFS" \
1515
_CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
1616
_CLAP_COMPLETE_COMP_TYPE="$_CLAP_COMPLETE_COMP_TYPE" \
17+
_CLAP_COMPLETE_SPACE="$_CLAP_COMPLETE_SPACE" \
1718
COMPLETE="bash" \
1819
"exhaustive" -- "${COMP_WORDS[@]}" \
1920
) )
2021
if [[ $? != 0 ]]; then
2122
unset COMPREPLY
22-
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
23+
elif [[ $_CLAP_COMPLETE_SPACE == false ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
2324
compopt -o nospace
2425
fi
2526
}

clap_complete/tests/snapshots/register_minimal.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _clap_complete_my_app() {
1717
) )
1818
if [[ $? != 0 ]]; then
1919
unset COMPREPLY
20-
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
20+
elif [[ $_CLAP_COMPLETE_SPACE == false ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
2121
compopt -o nospace
2222
fi
2323
}

clap_complete/tests/testsuite/bash.rs

+17
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,20 @@ fn complete_dynamic_empty_option_value() {
380380
let actual = runtime.complete(input, &term).unwrap();
381381
assert_data_eq!(actual, expected);
382382
}
383+
384+
#[test]
385+
#[cfg(all(unix, feature = "unstable-dynamic"))]
386+
#[cfg(feature = "unstable-shell-tests")]
387+
fn complete_dynamic_dir_no_trailing_space() {
388+
if !common::has_command(CMD) {
389+
return;
390+
}
391+
392+
let term = completest::Term::new();
393+
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
394+
395+
let input = "exhaustive hint --file test\t";
396+
let expected = snapbox::str!["exhaustive hint --file test % exhaustive hint --file tests/"];
397+
let actual = runtime.complete(input, &term).unwrap();
398+
assert_data_eq!(actual, expected);
399+
}

0 commit comments

Comments
 (0)