Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e247f2c authored by Luca Stefani's avatar Luca Stefani
Browse files

Add support for ZSH arrays

* ZSH arrays are one-based

Change-Id: Id14396283b77c15e9f0fc6f94628bf312f696006
parent cd9e2fcf
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -498,7 +498,7 @@ function choosevariant()
            export TARGET_BUILD_VARIANT=$default_value
        elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
            if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
                export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
                export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-$_arrayoffset))]}
            fi
        else
            if check_variant $ANSWER
@@ -596,7 +596,7 @@ function lunch()
    then
        if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
        then
            selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
            selection=${LUNCH_MENU_CHOICES[$(($answer-$_arrayoffset))]}
        fi
    else
        selection=$answer
@@ -1572,7 +1572,7 @@ function godir () {
                echo "Invalid choice"
                continue
            fi
            pathname=${lines[$(($choice-1))]}
            pathname=${lines[$(($choice-$_arrayoffset))]}
        done
    else
        pathname=${lines[0]}
@@ -1735,6 +1735,16 @@ if ! __detect_shell > /dev/null; then
    echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
fi

# determine whether arrays are zero-based (bash) or one-based (zsh)
_xarray=(a b c)
if [ -z "${_xarray[${#_xarray[@]}]}" ]
then
    _arrayoffset=1
else
    _arrayoffset=0
fi
unset _xarray

# Execute the contents of any vendorsetup.sh files we can find.
for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
         `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \