From 13a79804c958c5b58ac509f97edee9bf10aaad43 Mon Sep 17 00:00:00 2001 From: sudotac Date: Sun, 3 Dec 2023 17:27:00 +0900 Subject: [PATCH] fix(complete): Suppress a useless space completion --- clap_complete/src/shells/bash.rs | 1 + .../tests/snapshots/home/static/exhaustive/bash/.bashrc | 3 +++ clap_complete/tests/snapshots/value_hint.bash | 3 +++ clap_complete/tests/testsuite/bash.rs | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index ed15b1e8eea..cc9ce2a874e 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -171,6 +171,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String { let compopt = match o.get_value_hint() { ValueHint::FilePath => Some("compopt -o filenames"), ValueHint::DirPath => Some("compopt -o plusdirs"), + ValueHint::Other => Some("compopt -o nospace"), _ => None, }; diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc index 50f1b0ff0a1..2f72ccf40b2 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc +++ b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc @@ -542,6 +542,9 @@ _exhaustive() { ;; --other) COMPREPLY=("${cur}") + if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then + compopt -o nospace + fi return 0 ;; --path) diff --git a/clap_complete/tests/snapshots/value_hint.bash b/clap_complete/tests/snapshots/value_hint.bash index 19eba6b4bce..35f6b3d56b1 100644 --- a/clap_complete/tests/snapshots/value_hint.bash +++ b/clap_complete/tests/snapshots/value_hint.bash @@ -35,6 +35,9 @@ _my-app() { ;; --other) COMPREPLY=("${cur}") + if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then + compopt -o nospace + fi return 0 ;; --path) diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index a1f18a3e58f..7edb458cc9d 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -210,7 +210,7 @@ fn complete() { } 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(); snapbox::assert_eq(expected, actual); }