From cd82f8cc8e15e85a1a5c17da82fee6c32dc43e7d Mon Sep 17 00:00:00 2001 From: sudotac Date: Sun, 7 Apr 2024 23:19:50 +0900 Subject: [PATCH] fix(complete): Avoid use of -v in bash completion Because -v is not supported below bash 5.0. --- clap_complete/src/shells/bash.rs | 8 ++++---- .../tests/snapshots/home/static/exhaustive/bash/.bashrc | 8 ++++---- clap_complete/tests/snapshots/value_hint.bash | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index 5fb39f4b965..bf361313667 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -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(), ]); @@ -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(), ]); diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc index a004f9148fe..bfbaec6f95f 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc +++ b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc @@ -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 @@ -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 diff --git a/clap_complete/tests/snapshots/value_hint.bash b/clap_complete/tests/snapshots/value_hint.bash index e2a7f9efd37..b4cc16fab44 100644 --- a/clap_complete/tests/snapshots/value_hint.bash +++ b/clap_complete/tests/snapshots/value_hint.bash @@ -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 @@ -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