fix(complete): Suppress a useless space completion

This commit is contained in:
sudotac 2023-12-03 17:27:00 +09:00
parent e25b1abddf
commit 13a79804c9
4 changed files with 8 additions and 1 deletions

View file

@ -171,6 +171,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
let compopt = match o.get_value_hint() { let compopt = match o.get_value_hint() {
ValueHint::FilePath => Some("compopt -o filenames"), ValueHint::FilePath => Some("compopt -o filenames"),
ValueHint::DirPath => Some("compopt -o plusdirs"), ValueHint::DirPath => Some("compopt -o plusdirs"),
ValueHint::Other => Some("compopt -o nospace"),
_ => None, _ => None,
}; };

View file

@ -542,6 +542,9 @@ _exhaustive() {
;; ;;
--other) --other)
COMPREPLY=("${cur}") COMPREPLY=("${cur}")
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
compopt -o nospace
fi
return 0 return 0
;; ;;
--path) --path)

View file

@ -35,6 +35,9 @@ _my-app() {
;; ;;
--other) --other)
COMPREPLY=("${cur}") COMPREPLY=("${cur}")
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
compopt -o nospace
fi
return 0 return 0
;; ;;
--path) --path)

View file

@ -210,7 +210,7 @@ fn complete() {
} }
let input = "exhaustive hint --other \t"; let input = "exhaustive hint --other \t";
let expected = "exhaustive hint --other % exhaustive hint --other "; let expected = "exhaustive hint --other % exhaustive hint --other ";
let actual = runtime.complete(input, &term).unwrap(); let actual = runtime.complete(input, &term).unwrap();
snapbox::assert_eq(expected, actual); snapbox::assert_eq(expected, actual);
} }