From 54bc19691882e2dafcf094b5c87493b3eed8a852 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 30 Jan 2024 07:58:47 +0100 Subject: [PATCH] Only use fuzzy option completion if there is a leading - Commit b768b9d3f (Use fuzzy subsequence completion for options names as well, 2024-01-27) allowed completing "oa" to "--foobar", which is a false positive, especially because it hides other valid completions of non-option arguments. Let's at least require a leading dash again before completing option names. --- src/complete.rs | 3 +++ tests/checks/complete.fish | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/complete.rs b/src/complete.rs index 03ab564e9..0e1b09442 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -1435,6 +1435,9 @@ impl<'ctx> Completer<'ctx> { if whole_opt.len() < s.len() { continue; } + if !s.starts_with("-") { + continue; + } let anchor_start = !self.flags.fuzzy_match; let Some(r#match) = string_fuzzy_match_string(s, &whole_opt, anchor_start) else { continue; diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 931c2cc22..1270d1713 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -601,3 +601,5 @@ complete -C'complete_long_option --slo' complete complete_long_option -f -o an-old-option complete -C'complete_long_option -ao' # CHECK: -an-old-option +# But only if the user typed a dash +complete -C'complete_long_option lo'