From 02cc8d4390e2f398b3e87b4595863b70ebac36de Mon Sep 17 00:00:00 2001 From: reuben olinsky Date: Wed, 12 Jun 2024 00:44:01 -0700 Subject: [PATCH] fix: compgen -W expansion (#78) With additional testing we see that the word string passed to 'compgen -W' is not only split but first expanded. Correcting that fixes completion of arguments to 'complete -p', among various other commands. --- brush-core/src/completion.rs | 10 +--------- brush-shell/tests/cases/builtins/compgen.yaml | 7 +++++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/brush-core/src/completion.rs b/brush-core/src/completion.rs index 5f0aef78..3aa83a29 100644 --- a/brush-core/src/completion.rs +++ b/brush-core/src/completion.rs @@ -379,7 +379,7 @@ impl Spec { candidates.append(&mut expansions); } if let Some(word_list) = &self.word_list { - let mut words = split_string_using_ifs(word_list, shell); + let mut words = crate::expansion::full_expand_and_split_str(shell, word_list).await?; candidates.append(&mut words); } if let Some(function_name) = &self.function_name { @@ -943,11 +943,3 @@ fn get_completions_using_basic_lookup(shell: &Shell, context: &Context) -> Answe Answer::Candidates(candidates, ProcessingOptions::default()) } - -fn split_string_using_ifs>(s: S, shell: &Shell) -> Vec { - let ifs_chars: Vec = shell.get_ifs().chars().collect(); - s.as_ref() - .split(ifs_chars.as_slice()) - .map(|s| s.to_owned()) - .collect() -} diff --git a/brush-shell/tests/cases/builtins/compgen.yaml b/brush-shell/tests/cases/builtins/compgen.yaml index d98d2326..7b54e183 100644 --- a/brush-shell/tests/cases/builtins/compgen.yaml +++ b/brush-shell/tests/cases/builtins/compgen.yaml @@ -49,3 +49,10 @@ cases: declare myvar2=11 compgen -A variable myvar | sort + + - name: "compgen -W" + stdin: | + echo "1. Basic compgen -W" + compgen -W "one two three" -- t | sort + echo "2. compgen -W with expansion" + myvar=value compgen -W '${myvar}'