| 1 |
|
| 2 |
function _screenshot2() |
| 3 |
{ |
| 4 |
local cur prev opts cmds device_selected |
| 5 |
COMPREPLY=() |
| 6 |
cur="${COMP_WORDS[COMP_CWORD]}" |
| 7 |
prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 8 |
prevprev="${COMP_WORDS[COMP_CWORD-2]}" |
| 9 |
opts="-d -e -l -s" |
| 10 |
device_selected="" |
| 11 |
|
| 12 |
# if there are multiple devices plugged in, prompt the user to specify which |
| 13 |
# so that the list of installed packaged can be fetched from the device |
| 14 |
|
| 15 |
case "${prev}" in |
| 16 |
-d|-e) |
| 17 |
device_selected="${prev}" |
| 18 |
;; |
| 19 |
esac |
| 20 |
|
| 21 |
# use device set by serial number |
| 22 |
case "${prevprev}" in |
| 23 |
-s) |
| 24 |
device_selected="-s ${prev}" |
| 25 |
;; |
| 26 |
esac |
| 27 |
|
| 28 |
if [ -z "$device_selected" ] && [ "$prev" != "-s" ]; then |
| 29 |
local num_devices=$(( $(adb devices 2>/dev/null|wc -l) - 2 )) |
| 30 |
if [ "$num_devices" -gt "1" ]; then |
| 31 |
# With multiple devices, you must choose a device first. |
| 32 |
COMPREPLY=( $(compgen -W "-s" -- ${cur}) ) |
| 33 |
return 0 |
| 34 |
fi |
| 35 |
fi |
| 36 |
|
| 37 |
case "${cur}" in |
| 38 |
-*) |
| 39 |
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) |
| 40 |
return 0 |
| 41 |
;; |
| 42 |
esac |
| 43 |
|
| 44 |
case "${prev}" in |
| 45 |
-s) |
| 46 |
if [ -z "$device_selected" ]; then |
| 47 |
# Use 'adb devices' to list serial numbers. |
| 48 |
COMPREPLY=( $(compgen -W "$(adb devices|grep 'device$'|cut -f1)" -- ${cur} ) ) |
| 49 |
return 0 |
| 50 |
fi |
| 51 |
;; |
| 52 |
esac |
| 53 |
|
| 54 |
COMPREPLY=( $(compgen -o dirnames -- ${cur}) ) |
| 55 |
return 0 |
| 56 |
} |
| 57 |
complete -F _screenshot2 screenshot2 |
| 58 |
|
| 59 |
# Local variables: |
| 60 |
# mode: shell-script |
| 61 |
# sh-basic-offset: 4 |
| 62 |
# sh-indent-comment: t |
| 63 |
# indent-tabs-mode: nil |
| 64 |
# End: |
| 65 |
# ex: ts=4 sw=4 et filetype=sh |