fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
dcde198c9
master
1# Completions for Android adb command 2 3function __fish_adb_no_subcommand -d'Test if adb has yet to be given the subcommand' 4for iin ( commandline -xpc) 5if contains --$i connect disconnect devices push pull sync shell emu logcat install uninstall jdwp forward bugreport backup restore version help start-server kill-server remount reboot get-state get-serialno get-devpath status-window root usb tcpip ppp sideload reconnect unroot exec-out 6return 1 7end 8end 9return 0 10end 11 12function __fish_adb_get_devices -d'Run adb devices and parse output' 13# This seems reasonably portable for all the platforms adb runs on 14set -l procs( ps -Ao comm=| string match'adb' ) 15# Don't run adb devices unless the server is already started - it takes a while to init 16if set -q procs[ 1 ] 17adb devices -l| string replace -rf'(\S+).*product:(\S+).*model:(\S+).*' '$1'\t'$2 $3' 18end 19end 20 21function __fish_adb_get_tcpip_devices -d'Get list of devices connected via TCP/IP' 22__fish_adb_get_devices | string match -r'^\d+\.\d+\.\d+\.\d+:\d+\t.*' 23end 24 25function __fish_adb_run_command -d'Runs adb with any -s parameters already given on the command line' 26set -l sopt 27set -l sopt_is_next 28set -l cmd( commandline -pxc) 29set -e cmd[ 1 ] 30for iin $cmd 31if test -n " $sopt_is_next " 32set sopt -s$i 33break 34else 35switch $i 36case -s 37set sopt_is_next1 38end 39end 40end 41 42# If no -s option, see if there's a -d or -e instead 43if test -z " $sopt " 44if contains -- -d$cmd 45set sopt -d 46else if contains -- -e$cmd 47set sopt -e 48end 49end 50 51# adb returns CRLF (seemingly) so strip CRs 52adb $sopt shell$argv | string replace -a\r '' 53end 54 55function __fish_adb_list_packages 56# That "2\>" is to pass the redirection *to adb*. 57# It sends stderr from commands it executes to its stdout as well. 58# Why it does that, I don't know - crossing the streams is a bad idea (c.f. Ghostbusters) 59__fish_adb_run_command pm list packages2 \> /dev/null| string replace'package:' '' 60end 61 62function __fish_adb_list_uninstallable_packages 63# -3 doesn't exactly mean show uninstallable, but it's the closest you can get to with pm list 64__fish_adb_run_command pm list packages-3 | string replace'package:' '' 65end 66 67function __fish_adb_list_local_files 68set -l token( commandline -ct) * 69 70# Unquoted $token to expand the array 71# Return list of directories suffixed with '/' 72find $token -maxdepth0 -type d2> /dev/null| string replace -r'$' / 73# Return list of files 74find $token -maxdepth0 -type f -o -type l2> /dev/null 75end 76 77function __fish_adb_list_files 78set -l token( commandline -ct) 79 80# Have tab complete show initial / if nothing on current token 81if test -z " $token " 82set token / 83end 84 85# Return list of directories suffixed with '/' 86__fish_adb_run_command find -H" $token *" -maxdepth0 -type d2 \> /dev/null| string replace -r'$' / 87# Return list of files 88__fish_adb_run_command find -H" $token *" -maxdepth0 -type f2 \> /dev/null 89end 90 91function __fish_adb_list_bin 92# list all binary without group 93__fish_adb_run_command ls-1 /system/bin/2 \> /dev/null 94__fish_adb_run_command ls-1 /system/xbin/2 \> /dev/null 95 96end 97 98function __fish_adb_list_properties 99__fish_adb_run_command getprop| string match -rg'\[(.*)\]:' 100end 101 102# Generic options, must come before command 103complete -n __fish_adb_no_subcommand -c adb -o a -d'Listen on all network interfaces' 104complete -n __fish_adb_no_subcommand -c adb -o d -d'Use first USB device' 105complete -n __fish_adb_no_subcommand -c adb -o e -d'Use first TCP/IP device' 106complete -n __fish_adb_no_subcommand -c adb -o s -x -a"(__fish_adb_get_devices)" -d'Use device with given serial' 107complete -n __fish_adb_no_subcommand -c adb -o t -d'Use device with given transport id' 108complete -n __fish_adb_no_subcommand -c adb -o H -d'Name of adb server host' 109complete -n __fish_adb_no_subcommand -c adb -o P -d'Port of adb server' 110complete -n __fish_adb_no_subcommand -c adb -o L -d'Listen on given socket for adb server' 111 112# Commands 113complete -f -n __fish_adb_no_subcommand -c adb -a connect -d'Connect to device' 114complete -f -n __fish_adb_no_subcommand -c adb -a disconnect -d'Disconnect from device' 115complete -f -n __fish_adb_no_subcommand -c adb -a devices -d'List all connected devices' 116complete -f -n __fish_adb_no_subcommand -c adb -a push -d'Copy file to device' 117complete -f -n __fish_adb_no_subcommand -c adb -a pull -d'Copy file from device' 118complete -f -n __fish_adb_no_subcommand -c adb -a sync -d'Copy host->device only if changed' 119complete -f -n __fish_adb_no_subcommand -c adb -a shell -d'Run remote shell [command]' 120complete -f -n __fish_adb_no_subcommand -c adb -a emu -d'Run emulator console command' 121complete -f -n __fish_adb_no_subcommand -c adb -a logcat -d'View device log' 122complete -f -n __fish_adb_no_subcommand -c adb -a install -d'Install package' 123complete -f -n __fish_adb_no_subcommand -c adb -a uninstall -d'Uninstall package' 124complete -f -n __fish_adb_no_subcommand -c adb -a jdwp -d'List PIDs of processes hosting a JDWP transport' 125complete -f -n __fish_adb_no_subcommand -c adb -a forward -d'Port forwarding' 126complete -f -n __fish_adb_no_subcommand -c adb -a bugreport -d'Return bugreport information' 127complete -f -n __fish_adb_no_subcommand -c adb -a backup -d'Perform device backup' 128complete -f -n __fish_adb_no_subcommand -c adb -a restore -d'Restore device from backup' 129complete -f -n __fish_adb_no_subcommand -c adb -a version -d'Show adb version' 130complete -f -n __fish_adb_no_subcommand -c adb -a help -d'Show adb help' 131complete -f -n __fish_adb_no_subcommand -c adb -a wait-for-device -d'Block until device is online' 132complete -f -n __fish_adb_no_subcommand -c adb -a start-server -d'Ensure that there is a server running' 133complete -f -n __fish_adb_no_subcommand -c adb -a kill-server -d'Kill the server if it is running' 134complete -f -n __fish_adb_no_subcommand -c adb -a remount -d'Remounts the /system partition on the device read-write' 135complete -f -n __fish_adb_no_subcommand -c adb -a reboot -d'Reboots the device, optionally into the bootloader or recovery program' 136complete -f -n __fish_adb_no_subcommand -c adb -a get-state -d'Prints state of the device' 137complete -f -n __fish_adb_no_subcommand -c adb -a get-serialno -d'Prints serial number of the device' 138complete -f -n __fish_adb_no_subcommand -c adb -a get-devpath -d'Prints device path' 139complete -f -n __fish_adb_no_subcommand -c adb -a status-window -d'Continuously print the device status' 140complete -f -n __fish_adb_no_subcommand -c adb -a root -d'Restart the adbd daemon with root permissions' 141complete -f -n __fish_adb_no_subcommand -c adb -a unroot -d'Restart the adbd daemon without root permissions' 142complete -f -n __fish_adb_no_subcommand -c adb -a usb -d'Restart the adbd daemon listening on USB' 143complete -f -n __fish_adb_no_subcommand -c adb -a tcpip -d'Restart the adbd daemon listening on TCP' 144complete -f -n __fish_adb_no_subcommand -c adb -a ppp -d'Run PPP over USB' 145complete -f -n __fish_adb_no_subcommand -c adb -a sideload -d'Sideloads the given package' 146complete -f -n __fish_adb_no_subcommand -c adb -a reconnect -d'Kick current connection from host side and make it reconnect.' 147complete -f -n __fish_adb_no_subcommand -c adb -a exec-out -d'Execute a command on the device and send its stdout back' 148 149# install options 150complete -n'__fish_seen_subcommand_from install' -c adb -s l -d'Forward-lock the app' 151complete -n'__fish_seen_subcommand_from install' -c adb -s r -d'Reinstall the app keeping its data' 152complete -n'__fish_seen_subcommand_from install' -c adb -s s -d'Install on SD card instead of internal storage' 153complete -n'__fish_seen_subcommand_from install' -c adb -l algo -d'Algorithm name' 154complete -n'__fish_seen_subcommand_from install' -c adb -l key -d'Hex-encoded key' 155complete -n'__fish_seen_subcommand_from install' -c adb -l iv -d'Hex-encoded iv' 156complete -n'__fish_seen_subcommand_from install' -c adb -ka'(__fish_complete_suffix .apk)' 157 158# uninstall 159complete -n'__fish_seen_subcommand_from uninstall' -c adb -s k -d'Keep the data and cache directories' 160complete -n'__fish_seen_subcommand_from uninstall' -c adb -f -a"(__fish_adb_list_uninstallable_packages)" 161 162# devices 163complete -n'__fish_seen_subcommand_from devices' -c adb -f 164complete -n'__fish_seen_subcommand_from devices' -c adb -s l -d'Also list device qualifiers' 165 166# disconnect 167complete -n'__fish_seen_subcommand_from disconnect' -c adb -x -a"(__fish_adb_get_tcpip_devices)" -d'Device to disconnect' 168 169# backup 170complete -n'__fish_seen_subcommand_from backup' -c adb -s f -d'File to write backup data to' 171complete -n'__fish_seen_subcommand_from backup' -c adb -o apk -d'Enable backup of the .apks themselves' 172complete -n'__fish_seen_subcommand_from backup' -c adb -o noapk -d'Disable backup of the .apks themselves (default)' 173complete -n'__fish_seen_subcommand_from backup' -c adb -o obb -d'Enable backup of any installed apk expansion' 174complete -n'__fish_seen_subcommand_from backup' -c adb -o noobb -d'Disable backup of any installed apk expansion (default)' 175complete -n'__fish_seen_subcommand_from backup' -c adb -o shared -d'Enable backup of the device\'s shared storage / SD card contents' 176complete -n'__fish_seen_subcommand_from backup' -c adb -o noshared -d'Disable backup of the device\'s shared storage / SD card contents (default)' 177complete -n'__fish_seen_subcommand_from backup' -c adb -o all -d'Back up all installed applications' 178complete -n'__fish_seen_subcommand_from backup' -c adb -o system -d'Include system applications in -all (default)' 179complete -n'__fish_seen_subcommand_from backup' -c adb -o nosystem -d'Exclude system applications in -all' 180complete -n'__fish_seen_subcommand_from backup' -c adb -f -a"(__fish_adb_list_packages)" -d'Package(s) to backup' 181 182# reboot 183complete -n'__fish_seen_subcommand_from reboot' -c adb -x -a'bootloader recovery fastboot' 184 185# forward 186complete -n'__fish_seen_subcommand_from forward' -c adb -l list -d'List all forward socket connections' 187complete -n'__fish_seen_subcommand_from forward' -c adb -l no-rebind -d'Fails the forward if local is already forwarded' 188complete -n'__fish_seen_subcommand_from forward' -c adb -l remove -d'Remove a specific forward socket connection' 189complete -n'__fish_seen_subcommand_from forward' -c adb -l remove-all -d'Remove all forward socket connections' 190 191# sideload 192complete -n'__fish_seen_subcommand_from sideload' -c adb -k -xa'(__fish_complete_suffix .zip)' 193 194# reconnect 195complete -n'__fish_seen_subcommand_from reconnect' -c adb -x -a device -d'Kick current connection from device side and make it reconnect.' 196 197# commands that accept listing device files 198complete -n'__fish_seen_subcommand_from exec-out' -c adb -f -a"(__fish_adb_list_files)" -d'File on device' 199complete -n'__fish_seen_subcommand_from shell' -c adb -f -a"(__fish_adb_list_files)" -d'File on device' 200complete -n'__fish_seen_subcommand_from pull' -c adb -F -a"(__fish_adb_list_files)" -d'File on device' 201complete -n'__fish_seen_subcommand_from push' -c adb -ka"(__fish_adb_list_files)" -d'File on device' 202complete -n'__fish_seen_subcommand_from push' -c adb -ka"(__fish_adb_list_local_files)" 203 204# logcat 205complete -n'__fish_seen_subcommand_from logcat' -c adb -f 206# general options 207complete -n'__fish_seen_subcommand_from logcat' -c adb -s L -l last -d'Dump logs from prior to last reboot from pstore' 208complete -n'__fish_seen_subcommand_from logcat' -c adb -s b -l buffer -d' Request alternate ring buffer(s)' -xa'(__fish_append , main system radio events crash default all)' 209complete -n'__fish_seen_subcommand_from logcat' -c adb -s c -l clear -d'Clear (flush) the entire log and exit' 210complete -n'__fish_seen_subcommand_from logcat' -c adb -s d -d'Dump the log and then exit (don\'t block)' 211complete -n'__fish_seen_subcommand_from logcat' -c adb -l pid -d'Only print the logs for the given PID' 212complete -n'__fish_seen_subcommand_from logcat' -c adb -l wrap -d'Sleep for 2 hours or when buffer about to wrap whichever comes first' 213# formatting 214complete -n'__fish_seen_subcommand_from logcat' -c adb -s v -l format -d'Sets log print format verb and adverbs' -xa' brief help long process raw tag thread threadtime time color descriptive epoch monotonic printable uid usec UTC year zone' 215complete -n'__fish_seen_subcommand_from logcat' -c adb -s D -l dividers -d'Print dividers between each log buffer' 216complete -n'__fish_seen_subcommand_from logcat' -c adb -s B -l binary -d'Output the log in binary' 217# outfile files 218complete -n'__fish_seen_subcommand_from logcat' -c adb -s f -l file -d'Log to file instead of stdout' 219complete -n'__fish_seen_subcommand_from logcat' -c adb -s r -l rotate-kbytes -d'Rotate log every kbytes, requires -f' 220complete -n'__fish_seen_subcommand_from logcat' -c adb -s n -l rotate-count -d'Sets number of rotated logs to keep, default 4' 221complete -n'__fish_seen_subcommand_from logcat' -c adb -l id -d'If the given signature for logging changes, clear the associated files' 222# logd control 223complete -n'__fish_seen_subcommand_from logcat' -c adb -s g -l buffer-size -d'Get the size of the ring buffers within logd' 224complete -n'__fish_seen_subcommand_from logcat' -c adb -s G -l buffer-size -d'Set size of a ring buffer in logd' 225complete -n'__fish_seen_subcommand_from logcat' -c adb -s S -l statistics -d'Output statistics' 226complete -n'__fish_seen_subcommand_from logcat' -c adb -s p -l prune -d'Print prune rules' 227complete -n'__fish_seen_subcommand_from logcat' -c adb -s P -l prune -d'Set prune rules' 228# filtering 229complete -n'__fish_seen_subcommand_from logcat' -c adb -s s -d'Set default filter to silent' 230complete -n'__fish_seen_subcommand_from logcat' -c adb -s e -l regex -d'Only print lines where the log message matches' 231complete -n'__fish_seen_subcommand_from logcat' -c adb -s m -l max-count -d'Quit after print <count> lines' 232complete -n'__fish_seen_subcommand_from logcat' -c adb -l print -d'Print all message even if they do not matches, requires --regex and --max-count' 233complete -n'__fish_seen_subcommand_from logcat' -c adb -l uid -d'Only display log messages from UIDs present in the comma separate list <uids>' 234 235# commands that accept listing device binaries 236complete -n'__fish_seen_subcommand_from exec-out' -c adb -f -a"(__fish_adb_list_bin)" -d"Command on device" 237complete -n'__fish_seen_subcommand_from shell' -c adb -f -a"(__fish_adb_list_bin)" -d"Command on device" 238 239# setprop and getprop in shell 240complete -n'__fish_seen_subcommand_from setprop' -c adb -f -a"(__fish_adb_list_properties)" -d'Property to set' 241complete -n'__fish_seen_subcommand_from getprop' -c adb -f -a"(__fish_adb_list_properties)" -d'Property to get'