Skip to content

Commit

Permalink
Merge pull request #5444 from sudotac/fix-broken-completion-on-bash-4.0
Browse files Browse the repository at this point in the history
fix(complete): Avoid use of -v in bash completion
  • Loading branch information
epage committed Apr 9, 2024
2 parents 93d4045 + cd82f8c commit a78b953
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
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
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
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 a78b953

Please sign in to comment.