Skip to content

Instantly share code, notes, and snippets.

@WhoisGray
Last active February 17, 2025 07:03
Show Gist options
  • Select an option

  • Save WhoisGray/baacfe37bef7cdef8d7ca542f38d5eb1 to your computer and use it in GitHub Desktop.

Select an option

Save WhoisGray/baacfe37bef7cdef8d7ca542f38d5eb1 to your computer and use it in GitHub Desktop.
๐Ÿ“ Description: This Bash script provides a sleek and interactive way to list Android emulators, navigate through the list using arrow keys, and launch the selected emulator. Itโ€™s designed to simplify the development workflow and enhance productivity.
#!/bin/bash
# ๐Ÿš€ Mobile Emulator Launcher
# Author: WhoisGray
# ๐Ÿ“ Description: A script to list available Android emulators, let you select one using arrow keys,
# and launch the selected emulator seamlessly.
# ๐Ÿ› ๏ธ Define the path to the emulator command
EMULATOR_PATH="${ANDROID_HOME}/emulator/emulator"
# ๐Ÿ›‘ Check if the emulator command exists
if [[ ! -x $EMULATOR_PATH ]]; then
echo "โŒ Error: Emulator command not found at $EMULATOR_PATH."
echo "๐Ÿ’ก Please ensure ANDROID_HOME is correctly set."
exit 1
fi
# ๐Ÿ“‹ Fetch the list of available emulators
EMULATORS=$($EMULATOR_PATH -list-avds)
if [[ -z $EMULATORS ]]; then
echo "โš ๏ธ No emulators found. Please create one using the Android Virtual Device Manager."
exit 1
fi
# ๐Ÿ•น๏ธ Display the list of emulators in a menu
echo "๐Ÿ”ฝ Select an emulator to run:"
EMULATOR_ARRAY=($EMULATORS)
SELECTED_INDEX=0
while true; do
clear
echo "๐Ÿ“œ Available Emulators:"
for i in "${!EMULATOR_ARRAY[@]}"; do
if [[ $i -eq $SELECTED_INDEX ]]; then
echo "โžก๏ธ ${EMULATOR_ARRAY[i]}"
else
echo " ${EMULATOR_ARRAY[i]}"
fi
done
# ๐ŸŽฎ Read user input
read -rsn1 INPUT
case $INPUT in
A) # โฌ†๏ธ Up arrow
if [[ $SELECTED_INDEX -gt 0 ]]; then
SELECTED_INDEX=$((SELECTED_INDEX - 1))
fi
;;
B) # โฌ‡๏ธ Down arrow
if [[ $SELECTED_INDEX -lt $(( ${#EMULATOR_ARRAY[@]} - 1 )) ]]; then
SELECTED_INDEX=$((SELECTED_INDEX + 1))
fi
;;
"") # ๐Ÿ”„ Enter
SELECTED_EMULATOR="${EMULATOR_ARRAY[SELECTED_INDEX]}"
echo "๐Ÿš€ Starting emulator: $SELECTED_EMULATOR"
$EMULATOR_PATH -avd "$SELECTED_EMULATOR"
exit 0
;;
esac
done
@WhoisGray
Copy link
Author

๐Ÿš€ Mobile Emulator Launcher Script

๐Ÿ‘จโ€๐Ÿ’ป Author: WhoisGray

๐Ÿ“ Description

This Bash script offers a streamlined and interactive solution for managing Android Virtual Devices (AVDs). It lists available emulators, allows easy navigation using arrow keys, and launches the selected emulatorโ€”all in one command. Simplify your Android development workflow with this handy tool!

โœจ Features

  • ๐Ÿ“œ Automatically fetches and displays available Android emulators.
  • ๐ŸŽฎ Intuitive navigation through the emulator list using arrow keys.
  • ๐Ÿ› ๏ธ Graceful error handling for missing configurations or AVDs.

โš™๏ธ Prerequisites

  1. โœ… Ensure the ANDROID_HOME environment variable is set and points to your Android SDK directory.
  2. ๐Ÿ“‚ The Android SDK should include the emulator binaries.

๐Ÿš€ Usage

  1. Save the script as mobile.sh or your preferred name.
  2. Make it executable:
    chmod +x mobile.sh
  3. Add it to your PATH for global access, or execute it directly.
  4. Run the script with:
    mobile

๐Ÿ”– Tags

#bash #android #emulator #developer-tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment