Skip to content

Commit

Permalink
fix(complete): Avoid use of -v in bash completion
Browse files Browse the repository at this point in the history
Because -v is not supported below bash 5.0.
  • Loading branch information
sudotac committed Apr 7, 2024
1 parent 9d14f39 commit cd82f8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions clap_complete/src/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
if o.get_value_hint() == ValueHint::FilePath {
v.extend([
"local oldifs".to_string(),
"if [[ -v IFS ]]; then".to_string(),
r#"if [ -n "${IFS+x}" ]; then"#.to_string(),
r#" oldifs="$IFS""#.to_string(),
"fi".to_string(),
r#"IFS=$'\n'"#.to_string(),
format!("COMPREPLY=({})", vals_for(o)),
"if [[ -v oldifs ]]; then".to_string(),
r#"if [ -n "${oldifs+x}" ]; then"#.to_string(),
r#" IFS="$oldifs""#.to_string(),
"fi".to_string(),
]);
Expand Down Expand Up @@ -216,12 +216,12 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
if o.get_value_hint() == ValueHint::FilePath {
v.extend([
"local oldifs".to_string(),
"if [[ -v IFS ]]; then".to_string(),
r#"if [ -n "${IFS+x}" ]; then"#.to_string(),
r#" oldifs="$IFS""#.to_string(),
"fi".to_string(),
r#"IFS=$'\n'"#.to_string(),
format!("COMPREPLY=({})", vals_for(o)),
"if [[ -v oldifs ]]; then".to_string(),
r#"if [ -n "${oldifs+x}" ]; then"#.to_string(),
r#" IFS="$oldifs""#.to_string(),
"fi".to_string(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ _exhaustive() {
;;
--file)
local oldifs
if [[ -v IFS ]]; then
if [ -n "${IFS+x}" ]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
if [ -n "${oldifs+x}" ]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
Expand All @@ -572,12 +572,12 @@ _exhaustive() {
;;
-f)
local oldifs
if [[ -v IFS ]]; then
if [ -n "${IFS+x}" ]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
if [ -n "${oldifs+x}" ]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/snapshots/value_hint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ _my-app() {
;;
--file)
local oldifs
if [[ -v IFS ]]; then
if [ -n "${IFS+x}" ]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
if [ -n "${oldifs+x}" ]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
Expand All @@ -65,12 +65,12 @@ _my-app() {
;;
-f)
local oldifs
if [[ -v IFS ]]; then
if [ -n "${IFS+x}" ]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
if [ -n "${oldifs+x}" ]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
Expand Down

0 comments on commit cd82f8c

Please sign in to comment.