Skip to content

Commit acd00b2

Browse files
authored
Fix bash completion of candidates for install (#993)
The `read` built-in uses IFS for word delimiters, and `-d` for delimiting _where to stop reading_. We are parsing CSV, so the combination of `IFS= -d,` results in only the first word. Further, `read -a` fills an array variable so we don't need a loop.
1 parent 1129b07 commit acd00b2

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If the environment needs tweaking for SDKMAN to be installed, the installer will
1919

2020
## Running the Cucumber Features
2121

22-
All SDKMAN's BDD tests describing the CLI behaviour are written in Cucumber and can be found under `src/test/cucumber/sdkman`. These can be run with Gradle by running the following command:
22+
All SDKMAN's BDD tests describing the CLI behaviour are written in Cucumber and can be found under `src/test/resources/features`. These can be run with Gradle by running the following command:
2323

2424
$ ./gradlew test
2525

contrib/completion/bash/sdk

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ __sdkman_complete_command() {
1818
local -r command=$1
1919
local -r current_word=$2
2020

21-
local candidates
21+
local -a candidates
2222

2323
case $command in
2424
sdk)
@@ -33,10 +33,7 @@ __sdkman_complete_command() {
3333
;;
3434
install|list)
3535
local -r all_candidates=$(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")
36-
37-
while IFS= read -d, -r candidate; do
38-
candidates+=($candidate)
39-
done <<< "$all_candidates"
36+
IFS=',' read -r -a candidates <<< "$all_candidates"
4037
;;
4138
env)
4239
candidates=("init install clear")
@@ -60,7 +57,7 @@ __sdkman_complete_candidate_version() {
6057
local -r candidate=$2
6158
local -r candidate_version=$3
6259

63-
local candidates
60+
local -a candidates
6461

6562
case $command in
6663
use|default|home|uninstall)
@@ -74,10 +71,7 @@ __sdkman_complete_candidate_version() {
7471
;;
7572
install)
7673
local -r all_candidate_versions=$(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/$candidate/${SDKMAN_PLATFORM}/versions/all")
77-
78-
while IFS= read -d, -r version; do
79-
candidates+=($version)
80-
done <<< "$all_candidate_versions"
74+
IFS=',' read -r -a candidates <<< "$all_candidate_versions"
8175
;;
8276
esac
8377

0 commit comments

Comments
 (0)