Skip to content

Commit

Permalink
feat(complete): Add DirPath support in bash
Browse files Browse the repository at this point in the history
  • Loading branch information
sudotac committed Dec 3, 2023
1 parent b1d3f9e commit 7cfd921
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions clap_complete/src/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
for o in p.get_opts() {
let compopt = match o.get_value_hint() {
ValueHint::FilePath => Some("compopt -o filenames"),
ValueHint::DirPath => Some("compopt -o plusdirs"),
_ => None,
};

Expand Down Expand Up @@ -217,6 +218,8 @@ fn vals_for(o: &Arg) -> String {
.collect::<Vec<_>>()
.join(" ")
)
} else if o.get_value_hint() == ValueHint::DirPath {
String::from("$(compgen -d \"${cur}\")")
} else if o.get_value_hint() == ValueHint::Other {
String::from("\"${cur}\"")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,13 @@ _exhaustive() {
return 0
;;
--dir)
COMPREPLY=($(compgen -f "${cur}"))
COMPREPLY=($(compgen -d "${cur}"))
compopt -o plusdirs
return 0
;;
-d)
COMPREPLY=($(compgen -f "${cur}"))
COMPREPLY=($(compgen -d "${cur}"))
compopt -o plusdirs
return 0
;;
--exe)
Expand Down
6 changes: 4 additions & 2 deletions clap_complete/tests/snapshots/value_hint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ _my-app() {
return 0
;;
--dir)
COMPREPLY=($(compgen -f "${cur}"))
COMPREPLY=($(compgen -d "${cur}"))
compopt -o plusdirs
return 0
;;
-d)
COMPREPLY=($(compgen -f "${cur}"))
COMPREPLY=($(compgen -d "${cur}"))
compopt -o plusdirs
return 0
;;
--exe)
Expand Down

0 comments on commit 7cfd921

Please sign in to comment.