Skip to content

Commit 6edce81

Browse files
authored
fix: bash completion for values containing COMP_WORDBREAKS (#305)
1 parent fc972f4 commit 6edce81

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/compgen.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ impl Shell {
559559
}
560560
match self {
561561
Shell::Bash => match std::env::var("COMP_WORDBREAKS") {
562-
Ok(v) => v.chars().collect(),
562+
Ok(v) => [':', '=', '@']
563+
.iter()
564+
.filter(|c| v.contains(**c))
565+
.copied()
566+
.collect(),
563567
Err(_) => [':', '=', '@'].to_vec(),
564568
},
565569
Shell::Powershell => vec![','],

tests/compgen.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -955,22 +955,23 @@ fn break_chars_bash() {
955955
let script = r#"
956956
# @arg args[`_choice_fn`]
957957
_choice_fn() {
958-
echo abc:def
959-
echo abc:ghi
960-
echo abc=def
961-
echo abc=ghi
962-
echo abc@def
963-
echo abc@ghi
964-
echo abc,def
965-
echo abc,ghi
958+
echo "a1:b1"
959+
echo "a1:b2"
960+
echo "a1@b1"
961+
echo "a1@b2"
962+
echo "a1=b1"
963+
echo "a1=b2"
964+
echo "a1 b1"
965+
echo "a1 b2"
966966
}
967967
"#;
968968
snapshot_compgen!(
969969
script,
970970
[
971-
vec!["prog", "abc:"],
972-
vec!["prog", "abc="],
973-
vec!["prog", "abc@"],
971+
vec!["prog", "a1:b"],
972+
vec!["prog", "a1@b"],
973+
vec!["prog", "a1=b"],
974+
vec!["prog", "a1 b"],
974975
],
975976
argc::Shell::Bash
976977
);

tests/snapshots/integration__compgen__break_chars_bash.snap

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
source: tests/compgen.rs
33
expression: data
44
---
5-
************ COMPGEN `prog abc:` ************
6-
def
7-
ghi
5+
************ COMPGEN `prog a1:b` ************
6+
b1
7+
b2
88

9-
************ COMPGEN `prog abc=` ************
10-
def
11-
ghi
9+
************ COMPGEN `prog a1@b` ************
10+
@b1
11+
@b2
1212

13-
************ COMPGEN `prog abc@` ************
14-
@def
15-
@ghi
13+
************ COMPGEN `prog a1=b` ************
14+
b1
15+
b2
16+
17+
************ COMPGEN `prog a1 b` ************
18+
a1\ b1
19+
a1\ b2
1620

1721

0 commit comments

Comments
 (0)