## Bash completion for the Android SDK tools.
##
## Copyright (c) 2009 Matt Brubeck
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
## THE SOFTWARE.
function _android()
{
local cur prev opts cmds type types c subcommand
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --silent --verbose"
cmds="list create move delete update"
types="avd target project"
subcommand=""
type=""
# Look for the subcommand.
c=1
while [ $c -lt $COMP_CWORD ]; do
word="${COMP_WORDS[c]}"
for cmd in $cmds; do
if [ "$cmd" = "$word" ]; then
subcommand="$word"
fi
done
for w in $types; do
if [ "$w" = "$word" ]; then
type="$word"
fi
done
c=$((++c))
done
case "$subcommand $type" in
" ")
case "$cur" in
-*)
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
;;
esac
COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
;;
"list ")
COMPREPLY=( $(compgen -W "avd target" -- ${cur}) )
;;
"create "|"update ")
COMPREPLY=( $(compgen -W "avd project" -- ${cur}) )
;;
"move "|"delete ")
COMPREPLY=( $(compgen -W "avd" -- ${cur}) )
;;
esac
case "$cur" in
-*)
case "$subcommand $type" in
"delete ")
COMPREPLY=( $(compgen -W "avd" -- ${cur}) )
;;
"create avd")
COMPREPLY=( $(compgen -W "--target --sdcard --path --name --force --skin" -- ${cur}) )
;;
"move avd")
COMPREPLY=( $(compgen -W "--path --name --rename" -- ${cur}) )
;;
"delete avd"|"update avd")
COMPREPLY=( $(compgen -W "--name" -- ${cur}) )
;;
"create project")
COMPREPLY=( $(compgen -W "--package --name --activity --target --path" -- ${cur}) )
;;
"update project")
COMPREPLY=( $(compgen -W "--target --path --name" -- ${cur}) )
;;
esac
;;
esac
return 0
}
complete -o default -F _android android
function _adb()
{
local cur prev opts cmds c subcommand device_selected
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-d -e -s -p"
cmds="devices push pull sync shell emu logcat forward jdwp install \
uninstall bugreport help version wait-for-device start-server \
kill-server get-state get-serialno status-window remount root ppp"
subcommand=""
device_selected=""
# Look for the subcommand.
c=1
while [ $c -lt $COMP_CWORD ]; do
word="${COMP_WORDS[c]}"
if [ "$word" = "-d" -o "$word" = "-e" -o "$word" = "-s" ]; then
device_selected=true
opts="-p"
fi
for cmd in $cmds; do
if [ "$cmd" = "$word" ]; then
subcommand="$word"
fi
done
c=$((++c))
done
case "${subcommand}" in
'')
case "${prev}" in
-p)
return 0;
;;
-s)
# Use 'adb devices' to list serial numbers.
COMPREPLY=( $(compgen -W "$(adb devices|tail -n +2|head -n -1|cut -f1)" -- ${cur} ) )
return 0
;;
esac
case "${cur}" in
-*)
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return 0
;;
esac
if [ -z "$device_selected" ]; then
local num_devices=$(( $(adb devices 2>/dev/null|wc -l) - 2 ))
if [ "$num_devices" -gt "1" ]; then
# With multiple devices, you must choose a device first.
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
fi
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
return 0
;;
install)
case "${cur}" in
-*)
COMPREPLY=( $(compgen -W "-k -l" -- ${cur}) )
return 0
;;
esac
;;
forward)
# Filename or installation option.
COMPREPLY=( $(compgen -W "tcp: localabstract: localreserved: localfilesystem: dev: jdwp:" -- ${cur}) )
return 0
;;
uninstall)
case "${cur}" in
-*)
COMPREPLY=( $(compgen -W "-k" -- ${cur}) )
return 0
;;
esac
;;
logcat)
case "${cur}" in
-*)
COMPREPLY=( $(compgen -W "-v -b -c -d -f -g -n -r -s" -- ${cur}) )
return 0
;;
esac
case "${prev}" in
-v)
COMPREPLY=( $(compgen -W "brief process tag thread raw time long" -- ${cur}) )
return 0
;;
-b)
COMPREPLY=( $(compgen -W "radio events main" -- ${cur}) )
return 0
;;
esac
;;
esac
}
complete -o default -F _adb adb
function _emulator()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-system -datadir -kernel -ramdisk -init-data -data -partition-size -cache \
-no-cache -sdcard -wipe-data -avd -skindir -skin -no-skin -memory -netspeed -netdelay \
-netfast -trace -show-kernel -shell -no-jni -logcat -no-audio -audio \
-audio-in -audio-out -raw-keys -radio -port -ports -onion -onion-alpha \
-onion-rotation -scale -dpi-device -http-proxy -timezone -dns-server \
-cpu-delay -no-boot-anim -no-window -version -report-console -gps -keyset \
-shell-serial -old-system -tcpdump -bootchart -nand-limits -qemu -verbose -debug -help \
-help-disk-images -help-keys -help-debug-tags -help-char-devices \
-help-environment -help-keyset-file -help-virtual-device -help-sdk-images \
-help-build-images -help-all"
case "$cur" in
-*)
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return 0
;;
esac
}
complete -o default -F _emulator emulator