diff --git a/plugins/avd/README.md b/plugins/avd/README.md index 80a600fde..67853ffe3 100644 --- a/plugins/avd/README.md +++ b/plugins/avd/README.md @@ -20,6 +20,7 @@ not work as expected. ## Functions - `avds` - Lists all the AVDs + - `-s` will skip the AVD numbers at the beginning of each output line - `avd [-v] ` - Launches n-th AVD from the AVDs list printed by `avds` - `-v` will let stdout and stderr print to the console which is @@ -29,7 +30,7 @@ not work as expected. ## Aliases -- `emus` - Same as `avds` +- `emus [-s]` - Same as `avds [-s]` - `emu [-v] ` - Same as `avd [-v] ` ## Exemplary usage: diff --git a/plugins/avd/avd.plugin.zsh b/plugins/avd/avd.plugin.zsh index 95ccbafeb..9b4fe1a97 100644 --- a/plugins/avd/avd.plugin.zsh +++ b/plugins/avd/avd.plugin.zsh @@ -21,26 +21,50 @@ function find_emulator() { } function avds() { - local emulator_path - emulator_path=$(find_emulator) + _avds_usage() { + echo "Usage: avds [-s]" + } - # Print all AVDs and prepend each output line with a number, starting at 1. - eval "$emulator_path -list-avds" | grep -n '^' + local OPTIND o emulator_path cmd_to_execute skip_numbers + + while getopts ":s" o; do + case "$o" in + s) + skip_numbers=1;; + *) + _avds_usage; return;; + esac + done + + shift $((OPTIND-1)) + + emulator_path=$(find_emulator) + cmd_to_execute="$emulator_path -list-avds" + + if [[ $skip_numbers -eq 1 ]]; then + # Just print all AVDs. + eval "$cmd_to_execute" + else + # Print all AVDs and prepend each output line with a number, starting at 1. + eval "$cmd_to_execute" | grep -n '^' + fi } function avd() { - help() { + _avd_usage() { echo "Usage: avd [-v] [AVD position on the list]" avds } - local OPTIND o verbose avd_number avd_name avds_count emulator_path cmd_to_execute + local OPTIND o verbose avd_number avd_name avds_count emulator_path + local cmd_to_execute + while getopts ":v" o; do case "$o" in v) verbose=1;; *) - help; return;; + _avd_usage; return;; esac done @@ -49,7 +73,7 @@ function avd() { avd_number="$1" if [[ -z $avd_number ]]; then - help + _avd_usage return fi @@ -66,7 +90,7 @@ function avd() { fi # Print only the n-th AVD and remove the number prefix added by 'grep -n' - avd_name=$(avds | head -"$avd_number" | tail -1 | sed -E 's/^[0-9]+://') + avd_name=$(avds -s | head -"$avd_number" | tail -1) echo "Starting emulator: $avd_name" emulator_path=$(find_emulator)