Skip to content

Commit e25b1ab

Browse files
committed
feat(complete): Add DirPath support in bash
1 parent 3a222de commit e25b1ab

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

clap_complete/src/shells/bash.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
170170
for o in p.get_opts() {
171171
let compopt = match o.get_value_hint() {
172172
ValueHint::FilePath => Some("compopt -o filenames"),
173+
ValueHint::DirPath => Some("compopt -o plusdirs"),
173174
_ => None,
174175
};
175176

@@ -229,6 +230,8 @@ fn vals_for(o: &Arg) -> String {
229230
.collect::<Vec<_>>()
230231
.join(" ")
231232
)
233+
} else if o.get_value_hint() == ValueHint::DirPath {
234+
String::from("") // should be empty to avoid duplicate candidates
232235
} else if o.get_value_hint() == ValueHint::Other {
233236
String::from("\"${cur}\"")
234237
} else {

clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,17 @@ _exhaustive() {
567567
return 0
568568
;;
569569
--dir)
570-
COMPREPLY=($(compgen -f "${cur}"))
570+
COMPREPLY=()
571+
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
572+
compopt -o plusdirs
573+
fi
571574
return 0
572575
;;
573576
-d)
574-
COMPREPLY=($(compgen -f "${cur}"))
577+
COMPREPLY=()
578+
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
579+
compopt -o plusdirs
580+
fi
575581
return 0
576582
;;
577583
--exe)

clap_complete/tests/snapshots/value_hint.bash

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ _my-app() {
6060
return 0
6161
;;
6262
--dir)
63-
COMPREPLY=($(compgen -f "${cur}"))
63+
COMPREPLY=()
64+
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
65+
compopt -o plusdirs
66+
fi
6467
return 0
6568
;;
6669
-d)
67-
COMPREPLY=($(compgen -f "${cur}"))
70+
COMPREPLY=()
71+
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
72+
compopt -o plusdirs
73+
fi
6874
return 0
6975
;;
7076
--exe)

clap_complete/tests/testsuite/bash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ fn complete() {
200200
);
201201
let actual = runtime.complete(input.as_str(), &term).unwrap();
202202
assert!(
203-
actual.contains("a_file")
204-
&& actual.contains("b_file")
203+
!actual.contains("a_file")
204+
&& !actual.contains("b_file")
205205
&& actual.contains("c_dir")
206206
&& actual.contains("d_dir"),
207207
"Actual output:\n{}",

0 commit comments

Comments
 (0)