Skip to content

Commit ab14a41

Browse files
committed
Fixes longstanding array composition bug on zsh. (#210)
1 parent 629054d commit ab14a41

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/main/bash/sdkman-init.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ fi
4242

4343
export SDKMAN_CANDIDATES_DIR="${SDKMAN_DIR}/candidates"
4444

45-
# force zsh to behave well
46-
if [[ -n "$ZSH_VERSION" ]]; then
47-
setopt shwordsplit
48-
fi
49-
5045
# OS specific support (must be 'true' or 'false').
5146
cygwin=false;
5247
darwin=false;
@@ -66,6 +61,16 @@ case "$(uname)" in
6661
freebsd=true
6762
esac
6863

64+
# Determine shell
65+
zsh_shell=false;
66+
bash_shell=false;
67+
68+
if [[ -n "$ZSH_VERSION" ]]; then
69+
zsh_shell=true
70+
else
71+
bash_shell=true
72+
fi
73+
6974
# Source sdkman module scripts.
7075
for f in $(find "${SDKMAN_DIR}/src" -type f -name 'sdkman-*' -exec basename {} \;); do
7176
source "${SDKMAN_DIR}/src/${f}"
@@ -111,12 +116,6 @@ else
111116
fi
112117
fi
113118

114-
# Set the candidate array
115-
OLD_IFS="$IFS"
116-
IFS=","
117-
SDKMAN_CANDIDATES=(${SDKMAN_CANDIDATES_CSV})
118-
IFS="$OLD_IFS"
119-
120119
# determine if up to date
121120
SDKMAN_VERSION_FILE="${SDKMAN_DIR}/var/version"
122121
if [[ "$sdkman_beta_channel" != "true" && -f "$SDKMAN_VERSION_FILE" && -z "$(find "$SDKMAN_VERSION_FILE" -mmin +$((60*24)))" ]]; then
@@ -144,6 +143,16 @@ else
144143
fi
145144
fi
146145

146+
# Set the candidate array
147+
if [[ "$zsh_shell" == 'true' ]]; then
148+
SDKMAN_CANDIDATES=( ${(s:,:)SDKMAN_CANDIDATES_CSV} )
149+
else
150+
OLD_IFS="$IFS"
151+
IFS=","
152+
SDKMAN_CANDIDATES=(${SDKMAN_CANDIDATES_CSV})
153+
IFS="$OLD_IFS"
154+
fi
155+
147156
# The candidates are assigned to an array for zsh compliance, a list of words is not iterable
148157
# Arrays are the only way, but unfortunately zsh arrays are not backward compatible with bash
149158
# In bash arrays are zero index based, in zsh they are 1 based(!)

0 commit comments

Comments
 (0)