Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bash completion for values containing COMP_WORDBREAKS #305

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ impl Shell {
}
match self {
Shell::Bash => match std::env::var("COMP_WORDBREAKS") {
Ok(v) => v.chars().collect(),
Ok(v) => [':', '=', '@']
.iter()
.filter(|c| v.contains(**c))
.copied()
.collect(),
Err(_) => [':', '=', '@'].to_vec(),
},
Shell::Powershell => vec![','],
Expand Down
23 changes: 12 additions & 11 deletions tests/compgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,22 +955,23 @@ fn break_chars_bash() {
let script = r#"
# @arg args[`_choice_fn`]
_choice_fn() {
echo abc:def
echo abc:ghi
echo abc=def
echo abc=ghi
echo abc@def
echo abc@ghi
echo abc,def
echo abc,ghi
echo "a1:b1"
echo "a1:b2"
echo "a1@b1"
echo "a1@b2"
echo "a1=b1"
echo "a1=b2"
echo "a1 b1"
echo "a1 b2"
}
"#;
snapshot_compgen!(
script,
[
vec!["prog", "abc:"],
vec!["prog", "abc="],
vec!["prog", "abc@"],
vec!["prog", "a1:b"],
vec!["prog", "a1@b"],
vec!["prog", "a1=b"],
vec!["prog", "a1 b"],
],
argc::Shell::Bash
);
Expand Down
22 changes: 13 additions & 9 deletions tests/snapshots/integration__compgen__break_chars_bash.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
source: tests/compgen.rs
expression: data
---
************ COMPGEN `prog abc:` ************
def
ghi
************ COMPGEN `prog a1:b` ************
b1
b2

************ COMPGEN `prog abc=` ************
def
ghi
************ COMPGEN `prog a1@b` ************
@b1
@b2

************ COMPGEN `prog abc@` ************
@def
@ghi
************ COMPGEN `prog a1=b` ************
b1
b2

************ COMPGEN `prog a1 b` ************
a1\ b1
a1\ b2


Loading