Skip to content

Instantly share code, notes, and snippets.

@enzinier
Created March 5, 2017 02:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enzinier/1c9f33756be4aaf654d70f6357eb89a2 to your computer and use it in GitHub Desktop.
Save enzinier/1c9f33756be4aaf654d70f6357eb89a2 to your computer and use it in GitHub Desktop.
Run android emulator by command in terminal.
#! /bin/bash
# (@) start-android
# If the emulator command exists on this device, displays a list of emulators
# and prompts the user to start one
# ref. http://stackoverflow.com/questions/7837952/what-is-the-command-to-list-the-available-avdnames
# Check if the emulator command exists first
if ! type emulator > /dev/null; then
echo "emulator command not found"
exit 1
fi
# Gather emulators that exist on this computer
DEVICES=( $(emulator -list-avds 2>&1 ) )
# Display list of emulators
echo "Available Emulators
----------------------------------------"
N=1
for DEVICE in ${DEVICES[@]}
do
echo "$N) $DEVICE"
let N=$N+1
done
# Request an emulator to start
read -p "
Choose an emulator: " num
# If the input is valid, launch our emulator on a separate PID and exit
if [ $num -lt $N ] && [ $num -gt 0 ];
then
DEVICE=${DEVICES[$num-1]}
emulator "@$DEVICE" > /dev/null 2>&1 &
exit 0
else
echo "Invalid Entry : $num"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment