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.
This commit is contained in:
Johannes Altmanninger 2024-01-30 07:58:47 +01:00
parent 6f0894c652
commit 54bc196918
2 changed files with 5 additions and 0 deletions

View file

@ -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;

View file

@ -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'