From 1184fcd260f6030d88328310fdd93da4ae75d8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Gris?= Date: Sun, 31 Jul 2022 15:53:38 +0200 Subject: [PATCH 1/4] fix(completion): fix static analysis shellcheck errors In ./contrib/completion/bash/sdk line 36: candidates=${SDKMAN_CANDIDATES[@]} ^--------^ SC2178 (warning): Variable was used as an array but is now assigned a string. ^---------------------^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. In ./contrib/completion/bash/sdk line 52: COMPREPLY=($(compgen -W "${candidates[*]}" -- "$current_word")) ^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). In ./contrib/completion/bash/sdk line 79: COMPREPLY=($(compgen -W "${candidates[*]}" -- "$candidate_version")) ^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). For more information: https://www.shellcheck.net/wiki/SC2124 -- Assigning an array to a string! A... https://www.shellcheck.net/wiki/SC2178 -- Variable was used as an array but... https://www.shellcheck.net/wiki/SC2207 -- Prefer mapfile or read -a to spli... --- contrib/completion/bash/sdk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/bash/sdk b/contrib/completion/bash/sdk index a8765d51b..dcb2d1240 100644 --- a/contrib/completion/bash/sdk +++ b/contrib/completion/bash/sdk @@ -33,7 +33,7 @@ __sdkman_complete_command() { done ;; install|i|list|ls) - candidates=${SDKMAN_CANDIDATES[@]} + candidates=("${SDKMAN_CANDIDATES[@]}") ;; env|e) candidates=("init" "install" "clear") @@ -49,7 +49,7 @@ __sdkman_complete_command() { ;; esac - COMPREPLY=($(compgen -W "${candidates[*]}" -- "$current_word")) + read -r -a COMPREPLY < <(compgen -W "${candidates[*]}" -- "$current_word") } __sdkman_complete_candidate_version() { @@ -76,7 +76,7 @@ __sdkman_complete_candidate_version() { ;; esac - COMPREPLY=($(compgen -W "${candidates[*]}" -- "$candidate_version")) + read -r -a COMPREPLY < <(compgen -W "${candidates[*]}" -- "$candidate_version") } complete -o default -F _sdk sdk From 550eeb39a148112d4d7803ee7c4af6255a951870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Gris?= Date: Sun, 31 Jul 2022 16:09:56 +0200 Subject: [PATCH 2/4] fix(compgen): mapfile instead of read -a --- contrib/completion/bash/sdk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/sdk b/contrib/completion/bash/sdk index dcb2d1240..309bef696 100644 --- a/contrib/completion/bash/sdk +++ b/contrib/completion/bash/sdk @@ -49,7 +49,7 @@ __sdkman_complete_command() { ;; esac - read -r -a COMPREPLY < <(compgen -W "${candidates[*]}" -- "$current_word") + mapfile -t COMPREPLY < <(compgen -W "${candidates[*]}" -- "$current_word") } __sdkman_complete_candidate_version() { @@ -76,7 +76,7 @@ __sdkman_complete_candidate_version() { ;; esac - read -r -a COMPREPLY < <(compgen -W "${candidates[*]}" -- "$candidate_version") + mapfile -t COMPREPLY < <(compgen -W "${candidates[*]}" -- "$candidate_version") } complete -o default -F _sdk sdk From 4e97735f14eec808c9429261234ad4d8a01b17a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Gris?= Date: Mon, 1 Aug 2022 21:38:33 +0200 Subject: [PATCH 3/4] fix(posix): make old bash pleased in posix mode Replace process substitution by named fifo and background process --- contrib/completion/bash/sdk | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/sdk b/contrib/completion/bash/sdk index 309bef696..6f792ea0e 100644 --- a/contrib/completion/bash/sdk +++ b/contrib/completion/bash/sdk @@ -49,7 +49,11 @@ __sdkman_complete_command() { ;; esac - mapfile -t COMPREPLY < <(compgen -W "${candidates[*]}" -- "$current_word") + local fifo && fifo=$(mktemp -u) && { + compgen -W "${candidates[*]}" -- "$current_word" > "$fifo" & + mapfile -t COMPREPLY < "$fifo" + rm -f "$fifo" + } } __sdkman_complete_candidate_version() { @@ -76,7 +80,11 @@ __sdkman_complete_candidate_version() { ;; esac - mapfile -t COMPREPLY < <(compgen -W "${candidates[*]}" -- "$candidate_version") + local fifo && fifo=$(mktemp -u) && { + compgen -W "${candidates[*]}" -- "$candidate_version" > "$fifo" & + mapfile -t COMPREPLY < "$fifo" + rm -f "$fifo" + } } complete -o default -F _sdk sdk From c295446cbe83d74380727d764830000a0467ab50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Gris?= Date: Mon, 1 Aug 2022 22:01:00 +0200 Subject: [PATCH 4/4] fix(bash32): restore bash 3.2 compat replace mapfile with read -a --- contrib/completion/bash/sdk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/sdk b/contrib/completion/bash/sdk index 6f792ea0e..1a138120d 100644 --- a/contrib/completion/bash/sdk +++ b/contrib/completion/bash/sdk @@ -51,7 +51,7 @@ __sdkman_complete_command() { local fifo && fifo=$(mktemp -u) && { compgen -W "${candidates[*]}" -- "$current_word" > "$fifo" & - mapfile -t COMPREPLY < "$fifo" + IFS=$'\n' read -r -d '' -a COMPREPLY < "$fifo" rm -f "$fifo" } } @@ -82,7 +82,7 @@ __sdkman_complete_candidate_version() { local fifo && fifo=$(mktemp -u) && { compgen -W "${candidates[*]}" -- "$candidate_version" > "$fifo" & - mapfile -t COMPREPLY < "$fifo" + IFS=$'\n' read -r -d '' -a COMPREPLY < "$fifo" rm -f "$fifo" } }