Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invert if statements that could cause a unexpected short circuits #470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/gvm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

[ -n "$GVM_DEBUG" ] && {
[ -z "$GVM_DEBUG" ] || {
set -x
}

Expand Down
10 changes: 5 additions & 5 deletions binscripts/gvm-installer
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ GVM_DEST=${2:-$HOME}
GVM_NAME="gvm"
SRC_REPO=${SRC_REPO:-https://github.com/moovweb/gvm.git}

[ "$GVM_DEST" = "$HOME" ] && GVM_NAME=".gvm"
[ "$GVM_DEST" != "$HOME" ] || GVM_NAME=".gvm"

[ -d "$GVM_DEST/$GVM_NAME" ] && display_error \
[ ! -d "$GVM_DEST/$GVM_NAME" ] || display_error \
"Already installed! Remove old installation by running

rm -rf $GVM_DEST/$GVM_NAME"

[ -d "$GVM_DEST" ] || mkdir -p "$GVM_DEST" > /dev/null 2>&1 || display_error "Failed to create $GVM_DEST"
[ -z "$(which git)" ] && display_error "Could not find git
[ -n "$(which git)" ] || display_error "Could not find git

debian/ubuntu: apt-get install git
redhat/centos: yum install git
Expand Down Expand Up @@ -102,7 +102,7 @@ builtin cd "$GVM_DEST/$GVM_NAME" && git checkout --quiet "$BRANCH" 2> /dev/null

popd > /dev/null

[ -z "$GVM_NO_GIT_BAK" ] && mv "$GVM_DEST/$GVM_NAME/.git" "$GVM_DEST/$GVM_NAME/git.bak"
[ -n "$GVM_NO_GIT_BAK" ] || mv "$GVM_DEST/$GVM_NAME/.git" "$GVM_DEST/$GVM_NAME/git.bak"

source_line="[[ -s \"${GVM_DEST}/$GVM_NAME/scripts/gvm\" ]] && source \"${GVM_DEST}/$GVM_NAME/scripts/gvm\""
source_file="${GVM_DEST}/$GVM_NAME/scripts/gvm"
Expand Down Expand Up @@ -136,7 +136,7 @@ fi
echo "export GVM_ROOT=$GVM_DEST/$GVM_NAME" > "$GVM_DEST/$GVM_NAME/scripts/gvm"
echo ". \$GVM_ROOT/scripts/gvm-default" >> "$GVM_DEST/$GVM_NAME/scripts/gvm"
check_existing_go
[[ -s "$GVM_DEST/$GVM_NAME/scripts/gvm" ]] && source "$GVM_DEST/$GVM_NAME/scripts/gvm"
[[ ! -s "$GVM_DEST/$GVM_NAME/scripts/gvm" ]] || source "$GVM_DEST/$GVM_NAME/scripts/gvm"
echo "Installed GVM v${GVM_VERSION}"
echo
echo "Please restart your terminal session or to get started right away run"
Expand Down
4 changes: 2 additions & 2 deletions scripts/cross
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ display_list() {

command -v go &> /dev/null || display_fatal "Only available in versions after Go 1"

[ -z "$1" ] && display_list
[ -n "$1" ] || display_list

if [ ! -f "$GOROOT/pkg/tool/cross" ]; then
display_message "Installing x86, x86-64, and ARM commands"
Expand All @@ -38,7 +38,7 @@ fi

export GOOS=$1
shift
[ -z "$1" ] && display_usage && display_fatal "arch is not specified"
[ -n "$1" ] || display_usage && display_fatal "arch is not specified"
export GOARCH=$1

if [ ! -d "$GOROOT/pkg/${GOOS}_${GOARCH}" ]; then
Expand Down
58 changes: 29 additions & 29 deletions scripts/env/cd
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ cd() {
fi

# gather default environment settings, they can change at any time!
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving defaults..."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Resolving defaults..."
defaults_hash=( $(__gvm_read_environment_file "${GVM_ROOT}/environments/default") )
if [[ $? -eq 0 ]]; then
defaults_resolved=true
else
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find default environment. Falling back to system."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Can't find default environment. Falling back to system."
defaults_hash=( $(__gvm_read_environment_file "${GVM_ROOT}/environments/system") )
if [[ $? -eq 0 ]]; then
defaults_resolved=true
else
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find system environment."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Can't find system environment."
fi
fi

if [[ "${defaults_resolved}" == false ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving fallback go version and pkgset from all available."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Resolving fallback go version and pkgset from all available."
local fallback_go_version="$(__gvm_resolve_fallback_version)"
local fallback_go_pkgset="$(__gvm_resolve_fallback_pkgset "${fallback_go_version}")"


[[ "${GVM_DEBUG}" -eq 1 ]] && echo "======================================="
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "fallback_go_version => $fallback_go_version"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "fallback_go_pkgset => $fallback_go_pkgset"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "======================================="
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "======================================="
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "fallback_go_version => $fallback_go_version"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "fallback_go_pkgset => $fallback_go_pkgset"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "======================================="

defaults_hash=( $(setValueForKeyFakeAssocArray "gvm_go_name" "${fallback_go_version}" "${defaults_hash[*]}") )
defaults_hash=( $(setValueForKeyFakeAssocArray "gvm_pkgset_name" "${fallback_go_pkgset}" "${defaults_hash[*]}") )
Expand All @@ -96,10 +96,10 @@ cd() {
defaults_go_pkgset="$(valueForKeyFakeAssocArray "gvm_pkgset_name" "${defaults_hash[*]}")"


[[ "${GVM_DEBUG}" -eq 1 ]] && echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_name => $defaults_go_name"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_pkgset => $defaults_go_pkgset"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "defaults_go_name => $defaults_go_name"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "defaults_go_pkgset => $defaults_go_pkgset"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

if [[ "${GVM_DEBUG}" -eq 1 ]]; then
echo "Resolved default go: ${defaults_go_name:-[EMPTY]}"
Expand All @@ -109,19 +109,19 @@ cd() {
dot_go_version="$(__gvmp_find_closest_dot_go_version)"
rslt=$?

[[ "${GVM_DEBUG}" -eq 1 ]] && echo "---------------------------------------"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "dot_go_version => $dot_go_version"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_name => $defaults_go_name"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "---------------------------------------"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "---------------------------------------"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "dot_go_version => $dot_go_version"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "defaults_go_name => $defaults_go_name"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "---------------------------------------"

if [[ $rslt -eq 0 ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found dot_go_version: ${dot_go_version}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Found dot_go_version: ${dot_go_version}"
local use_goversion="$(__gvmp_read_dot_go_version "${dot_go_version}")"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_goversion}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Switching to: ${use_goversion}"
gvm use "${use_goversion}" || return 1
unset use_goversion
elif [[ -n "${defaults_go_name}" ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-version found. Using system or default go."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "No .go-version found. Using system or default go."
# gvm use --quiet "${defaults_go_name}" || return 1
# gvm use "${defaults_go_name}" || return 1
else
Expand All @@ -139,22 +139,22 @@ cd() {

dot_go_pkgset="$(__gvmp_find_closest_dot_go_pkgset)"
rslt=$?
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "--------------------------------"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "dot_go_pkgset => $dot_go_pkgset"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "--------------------------------"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "--------------------------------"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "dot_go_pkgset => $dot_go_pkgset"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "--------------------------------"
if [[ $rslt -eq 0 ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found .go-pkgset: ${dot_go_pkgset}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Found .go-pkgset: ${dot_go_pkgset}"
local use_gopkgset="$(__gvmp_read_dot_go_pkgset "${dot_go_pkgset}")"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_gopkgset}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Switching to: ${use_gopkgset}"
gvm pkgset use "${use_gopkgset}" || return 1
unset use_gopkgset
elif [[ -n "${defaults_go_pkgset}" ]];then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-pkgset found. Using system or default pkgset."
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "---------- defaults_go_pkgset => $defaults_go_pkgset ----------"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "No .go-pkgset found. Using system or default pkgset."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "---------- defaults_go_pkgset => $defaults_go_pkgset ----------"
# gvm pkgset use --quiet "${defaults_go_pkgset}" || return 1
else
# quietly failing
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No fallback pkgset could be found."
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "No fallback pkgset could be found."
fi

return 0
Expand Down Expand Up @@ -185,7 +185,7 @@ __gvmp_read_dot_go_version() {

while IFS=$'\n' read -r _line; do
# skip comment lines
[[ "${_line}" =~ \#.* ]] && continue
[[ ! "${_line}" =~ \#.* ]] || continue

# looking for pattern "go1.2[.3]"
if [[ "${_line}" =~ ${regex} ]]; then
Expand All @@ -211,7 +211,7 @@ __gvmp_read_dot_go_pkgset() {

while IFS=$'\n' read -r _line; do
# skip comment lines
[[ "${_line}" =~ \#.* ]] && continue
[[ ! "${_line}" =~ \#.* ]] || continue

# fairly loose naming convention, exclude @ symbol
if [[ "${_line}" =~ ${regex} ]]; then
Expand Down
42 changes: 21 additions & 21 deletions scripts/env/pkgset-use
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ gvm_pkgset_use() {
local local_pkgset_regex="^(\/[^:\\\n\\\0]*)+$"
local pkgset_rematch local_pkgset_rematch

[[ "${GVM_DEBUG}" -eq 1 ]] && echo "gvm_pkgset_use: \$@ => $@"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "gvm_pkgset_use: \$@ => $@"
for _option in "${@}"; do
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Parsing ${FUNCNAME[0]}() argument: ${_option:-[EMPTY]}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Parsing ${FUNCNAME[0]}() argument: ${_option:-[EMPTY]}"

# if the accumulator has a trailing option flag (that is, the option
# flag has been specified but no argument has been supplied) then make
# sure the next _option value is not another option flag.
if [[ $(( ${#accumulator[@]}%2 )) -eq 1 && "${_option}" =~ ^[\-]+ ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Missing argument for: '${accumulator[${#accumulator[@]}-1]}'"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Missing argument for: '${accumulator[${#accumulator[@]}-1]}'"
return 1
fi

# scan pkgset_rematch checks exactly once each time through
pkgset_rematch=false
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "_option: ${_option}, pkgset_regex: ${pkgset_regex}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "_option: ${_option}, pkgset_regex: ${pkgset_regex}"
if __gvm_rematch "${_option}" "${pkgset_regex}"; then
pkgset_rematch=true
fi
Expand All @@ -80,9 +80,9 @@ gvm_pkgset_use() {
if [[ "${pkgset_rematch}" == true ]] && [[ $(( ${#accumulator[@]}%2 )) -eq 0 ]]; then
# if the regex matches and the accumulator is even, we can add the
# key/val pair.
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "========================"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "GVM_REMATCH => $GVM_REMATCH"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "========================"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "========================"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "GVM_REMATCH => $GVM_REMATCH"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "========================"
accumulator+=( "--pkgset" "${GVM_REMATCH[1]}" )
elif [[ "${pkgset_rematch}" == true ]] && [[ ${#accumulator[@]} -gt 0 && "${accumulator[${#accumulator[@]}-1]}" == "--pkgset" ]]; then
# if the regex matches and the accumulator is odd, the previous
Expand Down Expand Up @@ -169,9 +169,9 @@ gvm_pkgset_use() {

[[ -n "$gvm_go_name" ]] || display_error "No Go version selected" || return 1

[[ "${GVM_DEBUG}" -eq 1 ]] && echo "++++++++"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "options_hash => ${options_hash[*]}"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "++++++++"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "++++++++"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "options_hash => ${options_hash[*]}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "++++++++"

if [[ -n "$(valueForKeyFakeAssocArray "--local" "${options_hash[*]}")" ]]; then
local local_pkgset="$(valueForKeyFakeAssocArray "--local" "${options_hash[*]}")"
Expand All @@ -186,7 +186,7 @@ gvm_pkgset_use() {
display_error "Cannot find local package set" || return 1

local_pkgset="${local_pkgset}/.gvm_local"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolved local directory: ${local_pkgset}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Resolved local directory: ${local_pkgset}"

fuzzy_match=$($LS_PATH -1 "$local_pkgset/environments" | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "local" | $HEAD_PATH -n 1)
[[ -n "${fuzzy_match}" ]] || display_error "Cannot find local package set" || return 1
Expand All @@ -202,7 +202,7 @@ gvm_pkgset_use() {

# fix PATH to correct order
local fixed_path="$(__gvm_munge_path)"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
export PATH="${fixed_path}"
unset fixed_path

Expand All @@ -215,18 +215,18 @@ gvm_pkgset_use() {
elif [[ -n "$(valueForKeyFakeAssocArray "--pkgset" "${options_hash[*]}")" ]]; then
local pkgset="$(valueForKeyFakeAssocArray "--pkgset" "${options_hash[*]}")"

[[ "${GVM_DEBUG}" -eq 1 ]] && echo "=================="
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "gvm_go_name => $gvm_go_name"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "pkgset => $pkgset"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "=================="
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "=================="
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "gvm_go_name => $gvm_go_name"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "pkgset => $pkgset"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "=================="

[[ "${GVM_DEBUG}" -eq 1 ]] && echo "$LS_PATH -1 "$GVM_ROOT/environments" | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "${pkgset}" | $HEAD_PATH -n 1"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "$LS_PATH -1 "$GVM_ROOT/environments" | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "${pkgset}" | $HEAD_PATH -n 1"
fuzzy_match=$($LS_PATH -1 "$GVM_ROOT/environments" | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "${pkgset}" | $HEAD_PATH -n 1)
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "fuzzy_match => $fuzzy_match"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "fuzzy_match => $fuzzy_match"
# [[ -n "${fuzzy_match}" ]] || display_error "Invalid package set: ${pkgset}" || return 1
if [[ -z "${fuzzy_match}" ]]; then
gvm use --quiet $gvm_go_name
[[ "${GVM_DEBUG}" -eq 1 ]] && echo ">>>>>>>> gvm pkgset create $pkgset <<<<<<<"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo ">>>>>>>> gvm pkgset create $pkgset <<<<<<<"
gvm pkgset create $pkgset
gvm pkgset use --quiet $pkgset
fi
Expand All @@ -237,13 +237,13 @@ gvm_pkgset_use() {

# fix PATH to correct order
local fixed_path="$(__gvm_munge_path)"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
export PATH="${fixed_path}"
unset fixed_path

if [[ -n "$(valueForKeyFakeAssocArray "--default" "${options_hash[*]}")" ]]; then
cp "$GVM_ROOT/environments/$fuzzy_match" "$GVM_ROOT/environments/default"
[[ $? -ne 0 ]] && display_error "Couldn't make $fuzzy_match default"
[[ $? -eq 0 ]] || display_error "Couldn't make $fuzzy_match default"
fi

if [[ -z "$(valueForKeyFakeAssocArray "--quiet" "${options_hash[*]}")" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions scripts/env/use
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ gvm_use() {

for _option in "${@}"
do
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Parsing ${FUNCNAME[0]}() argument: ${_option:-[EMPTY]}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Parsing ${FUNCNAME[0]}() argument: ${_option:-[EMPTY]}"

# if the accumulator has a trailing option flag (that is, the option
# flag has been specified but no argument has been supplied) then make
Expand Down Expand Up @@ -220,14 +220,14 @@ gvm_use() {

# fix PATH to correct order
local fixed_path="$(__gvm_munge_path)"
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
[[ "${GVM_DEBUG}" -ne 1 ]] || echo "Original path: $PATH" && echo "Munged path: ${fixed_path}"
export PATH="${fixed_path}"
unset fixed_path

if [[ -n "$(valueForKeyFakeAssocArray "--default" "${options_hash[*]}")" ]]
then
cp "$GVM_ROOT/environments/$fuzzy_match" "$GVM_ROOT/environments/default"
[[ $? -ne 0 ]] && display_error "Couldn't make $fuzzy_match default"
[[ $? -eq 0 ]] || display_error "Couldn't make $fuzzy_match default"
fi

local pkgset="$(valueForKeyFakeAssocArray "--pkgset" "${options_hash[*]}")"
Expand Down
2 changes: 1 addition & 1 deletion scripts/function/_bash_pseudo_hash
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ setValueForKeyFakeAssocArray() {
unset i _target_ary_length

# key not found, append
[[ "${found}" == false ]] && target_ary+=( "${target_key}:${_encoded_new_value}" )
[[ "${found}" != false ]] || target_ary+=( "${target_key}:${_encoded_new_value}" )

printf "%s" "${target_ary[*]}"

Expand Down
4 changes: 2 additions & 2 deletions scripts/function/_shell_compat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[[ ${GVM_SHELL_COMPAT:-} -eq 1 ]] && return || readonly GVM_SHELL_COMPAT=1

# force zsh to start arrays at index 0
# [[ -n $ZSH_VERSION ]] && setopt KSH_ARRAYS
# [[ -z $ZSH_VERSION ]] || setopt KSH_ARRAYS

# __gvm_is_function()
# /*!
Expand All @@ -16,7 +16,7 @@
__gvm_is_function() {
local func_name="${1}"

[[ "x${func_name}" == "x" ]] && return 1
[[ "x${func_name}" != "x" ]] || return 1

# using 'declare -f' is the most reliable way for both bash and zsh!
builtin declare -f "${1}" >/dev/null
Expand Down
9 changes: 6 additions & 3 deletions scripts/function/locale_text
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ locale_text_for_key() {
local text_path="${GVM_ROOT}/locales"
local text_key_path="${text_path}/${text_locale}_${text_key}.txt"

[[ "x${text_key}" == "x" || ! -r "${text_key_path}" ]] && echo "" && return 1
if [[ "x${text_key}" == "x" || ! -r "${text_key_path}" ]]; then
echo ""
return 1
fi

local line_count=0
local text=""
while IFS= read -r _line; do
(( line_count++ ))
[[ "${line_count}" -gt 10 ]] && break
[[ "${line_count}" -lt 11 ]] || break
text+="${_line}"$'\n'
done <<< "$(cat "${text_key_path}")"

[[ -z "${line_count// }" ]] && text=""
[[ -n "${line_count// }" ]] || text=""

echo "${text}"

Expand Down
4 changes: 2 additions & 2 deletions scripts/function/munge_path
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ __gvm_munge_path() {
for (( i=0; i<${#path_out_ary[@]}; i++ ))
do
local __element="${path_out_ary[i]}"
[[ -n "${__element}" ]] && _dedupe_path_out_ary+=( "${__element}" )
[[ -z "${__element}" ]] || _dedupe_path_out_ary+=( "${__element}" )
# reset duplicates to an empty string so we can ignore them
for (( j=${#path_out_ary[@]}-1; j>i; j-- ))
do
[[ "${__element}" == "${path_out_ary[j]}" ]] && path_out_ary[j]=""
[[ "${__element}" != "${path_out_ary[j]}" ]] || path_out_ary[j]=""
done
unset __element
done
Expand Down
Loading