1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-01 09:41:44 +02:00

49966: _adb: Parse device spec correctly

This was particularly annoying when trying to complete logtags after adb logcat -s
This commit is contained in:
Mikael Magnusson 2022-04-03 18:34:02 +02:00
parent 6900dded09
commit 8537738207
2 changed files with 8 additions and 6 deletions

View file

@ -20,6 +20,9 @@
* 49965: Completion/Unix/Command/_adb: _adb: use $CURRENT instead * 49965: Completion/Unix/Command/_adb: _adb: use $CURRENT instead
of $#words of $#words
* 49966: Completion/Unix/Command/_adb: _adb: Parse device spec
correctly
2022-04-02 dana <dana@dana.is> 2022-04-02 dana <dana@dana.is>
* unposted (see 48073): Completion/Zsh/Command/_fc: Complete * unposted (see 48073): Completion/Zsh/Command/_fc: Complete

View file

@ -82,6 +82,7 @@ _adb() {
if ! adb ${ADB_DEVICE_SPECIFICATION} shell exit 2>/dev/null; then if ! adb ${ADB_DEVICE_SPECIFICATION} shell exit 2>/dev/null; then
# early bail-out until a single valid device/emulator is specified and up-and-running # early bail-out until a single valid device/emulator is specified and up-and-running
[[ $words[CURRENT-1] = -s ]] || _message -r "No (started) device specified, completions do not yet work" [[ $words[CURRENT-1] = -s ]] || _message -r "No (started) device specified, completions do not yet work"
#TODO handle -t transport-id
_arguments \ _arguments \
'-s[serial]: :_adb_device_serial' \ '-s[serial]: :_adb_device_serial' \
'( -e)-d[device]' \ '( -e)-d[device]' \
@ -165,13 +166,11 @@ _adb_sanitize_context () {
(( $+functions[_adb_device_specification] )) || (( $+functions[_adb_device_specification] )) ||
_adb_device_specification () { _adb_device_specification () {
local -a word if [[ $words[2] == -[de] ]]; then
word=($words[(R)-[des]]) ADB_DEVICE_SPECIFICATION=($words[2])
if [[ $words[(R)-s] == -s ]]; then elif [[ $words[2] == -[st] ]]; then
local i=$words[(I)-s] ADB_DEVICE_SPECIFICATION=($words[2,3])
word=($words[i,i+1])
fi fi
ADB_DEVICE_SPECIFICATION=($word)
} }
(( $+functions[_adb_dispatch_shell] )) || (( $+functions[_adb_dispatch_shell] )) ||