From 31e023fb02e0a9ca236943095d1489c6984d1925 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 b93d1088bcf7..d2716098fc82 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 9e173815db03..dd3db7932b2a 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]:-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 9b80e019dd3e..23efbfa5eb1a 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]:-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 35d98567cca2..8ed0990ca34a 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -202,7 +202,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); }