Skip to content

Commit 00298d9

Browse files
committed
more zsh array fixes
1 parent 3a5c9dd commit 00298d9

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@
1616

1717
[[ -z $CS_DEBUG ]] && CS_DEBUG=0
1818
SSH_CONFIG="$HOME/.ssh/config"
19-
VERSION="v1.7"
20-
# set -o errexit
21-
# set -o nounset
22-
# set -o pipefail
23-
24-
# Determine the shell that the script is being run from
25-
# if [[ "$SHELL" == "/bin/zsh" ]]; then
26-
# Zsh is running, set offset to 1
27-
# offset=1
28-
# else
29-
# Bash is running, set offset to 0
30-
offset=0
31-
# fi
19+
VERSION="v1.8"
20+
# ensure brace expansion is on for the shell
21+
set -o braceexpand && [[ $CS_DEBUG -eq 1 ]] && set -o && echo "$SHELL"
22+
# ensure Zsh uses zero-based arrays
23+
[[ "$SHELL" == "/bin/zsh" ]] && zsh -c 'emulate -LR zsh; setopt ksharrays; setopt' && [[ $CS_DEBUG -eq 1 ]] && echo "$SHELL"
3224

3325
# -------------------------- LIBRARIES
3426

@@ -63,7 +55,7 @@ lib-error-check() {
6355
local error_message="${2:-}"
6456
if (( exit_code != 0 )); then
6557
lib-debug
66-
if [ -n "$error_message" ]; then
58+
if [[-n "$error_message" ]]; then
6759
lib-msg "exit code: $exit_code, from: $error_message"
6860
fi
6961
exit "$exit_code"
@@ -72,10 +64,10 @@ lib-error-check() {
7264

7365
# display debug info
7466
lib-debug() {
75-
if [ -n "$ZSH_VERSION" ]; then
76-
lib-msg "${funcstack[$offset+1]}(${funcline[$offset]}) - ARGS: $*"
67+
if [[ "$SHELL" == "/bin/zsh" ]]; then
68+
lib-msg "${funcstack[1]}(${funcline[0]}) - ARGS: $*"
7769
else
78-
lib-msg "${FUNCNAME[$offset+1]}(${BASH_LINENO[$offset]}) - ARGS: $*"
70+
lib-msg "${FUNCNAME[1]}(${BASH_LINENO[0]}) - ARGS: $*"
7971
fi
8072
}
8173

@@ -221,7 +213,7 @@ eks-clusters() {
221213
instanceType=$(echo "$node_group_info" | jq -r '.instanceType')
222214
version=$(echo "$node_group_info" | jq -r '.version')
223215

224-
[[ $CS_DEBUG == 1 ]] && echo "$node_group_info"
216+
[[ $CS_DEBUG -eq 1 ]] && echo "$node_group_info"
225217
cs-print-row "$cluster_name" "$cluster_status" "$node_group_name" "$node_group_status" "$min_size" "$max_size" "$desired_size" "$type" "$instanceType" "$version"
226218
done
227219
done
@@ -542,9 +534,10 @@ cs-ec2-go() {
542534

543535
# capture input array
544536
userCommand=("$@") || lib-error-check 1 "Error executing user command: ${userCommand[*]}"
537+
[[ $CS_DEBUG -eq 1 ]] && echo "$@" && echo "${userCommand[0]}" && exit 0
545538

546-
for c in ${userCommand[$offset]}; do
547-
[[ $CS_DEBUG == 1 ]] && echo "$c"
539+
for c in ${userCommand[0]}; do
540+
[[ $CS_DEBUG -eq 1 ]] && echo "$c"
548541
if [[ $c == "-v" ]] || [[ $c == "--version" ]]; then
549542
cs-version $VERSION
550543
elif [[ $c == "--help" ]]; then

0 commit comments

Comments
 (0)