mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
feat(avd): use an explicit parameter to skip the numbering
This commit is contained in:
parent
e8e8ed7136
commit
150e98e22c
2 changed files with 35 additions and 10 deletions
|
@ -20,6 +20,7 @@ not work as expected.
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
- `avds` - Lists all the AVDs
|
- `avds` - Lists all the AVDs
|
||||||
|
- `-s` will skip the AVD numbers at the beginning of each output line
|
||||||
- `avd [-v] <n>` - Launches n-th AVD from the AVDs list printed by
|
- `avd [-v] <n>` - Launches n-th AVD from the AVDs list printed by
|
||||||
`avds`
|
`avds`
|
||||||
- `-v` will let stdout and stderr print to the console which is
|
- `-v` will let stdout and stderr print to the console which is
|
||||||
|
@ -29,7 +30,7 @@ not work as expected.
|
||||||
|
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
- `emus` - Same as `avds`
|
- `emus [-s]` - Same as `avds [-s]`
|
||||||
- `emu [-v] <n>` - Same as `avd [-v] <n>`
|
- `emu [-v] <n>` - Same as `avd [-v] <n>`
|
||||||
|
|
||||||
## Exemplary usage:
|
## Exemplary usage:
|
||||||
|
|
|
@ -21,26 +21,50 @@ function find_emulator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function avds() {
|
function avds() {
|
||||||
local emulator_path
|
_avds_usage() {
|
||||||
emulator_path=$(find_emulator)
|
echo "Usage: avds [-s]"
|
||||||
|
}
|
||||||
|
|
||||||
# Print all AVDs and prepend each output line with a number, starting at 1.
|
local OPTIND o emulator_path cmd_to_execute skip_numbers
|
||||||
eval "$emulator_path -list-avds" | grep -n '^'
|
|
||||||
|
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() {
|
function avd() {
|
||||||
help() {
|
_avd_usage() {
|
||||||
echo "Usage: avd [-v] [AVD position on the list]"
|
echo "Usage: avd [-v] [AVD position on the list]"
|
||||||
avds
|
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
|
while getopts ":v" o; do
|
||||||
case "$o" in
|
case "$o" in
|
||||||
v)
|
v)
|
||||||
verbose=1;;
|
verbose=1;;
|
||||||
*)
|
*)
|
||||||
help; return;;
|
_avd_usage; return;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -49,7 +73,7 @@ function avd() {
|
||||||
avd_number="$1"
|
avd_number="$1"
|
||||||
|
|
||||||
if [[ -z $avd_number ]]; then
|
if [[ -z $avd_number ]]; then
|
||||||
help
|
_avd_usage
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -66,7 +90,7 @@ function avd() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print only the n-th AVD and remove the number prefix added by 'grep -n'
|
# 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"
|
echo "Starting emulator: $avd_name"
|
||||||
|
|
||||||
emulator_path=$(find_emulator)
|
emulator_path=$(find_emulator)
|
||||||
|
|
Loading…
Reference in a new issue