Envsetup: Fix lunch choice with number in zsh
(zsh)$ source build/envsetup.sh; lunch 23
will result in selecting #22 because array in zsh starts from 1
instead of 0. This CL is to fix this issue.
Bug: b/117202855
Test: below commands should have the same output:
(zsh)$ source build/envsetup.sh; lunch 23
(zsh)$ source build/envsetup.sh; lunch aosp_walleye-userdebug
Change-Id: I0570585417878bc7c73eda0e1a416232fe147fb4
diff --git a/envsetup.sh b/envsetup.sh
index 5894144..5cbd9eb 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -585,7 +585,13 @@
local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
if [ $answer -le ${#choices[@]} ]
then
- selection=${choices[$(($answer-1))]}
+ # array in zsh starts from 1 instead of 0.
+ if [ -n "$ZSH_VERSION" ]
+ then
+ selection=${choices[$(($answer))]}
+ else
+ selection=${choices[$(($answer-1))]}
+ fi
fi
else
selection=$answer