* [PATCH] New, extended completion for lsusb
@ 2009-02-27 10:18 Jörg Sommer
0 siblings, 0 replies; only message in thread
From: Jörg Sommer @ 2009-02-27 10:18 UTC (permalink / raw)
To: zsh-workers; +Cc: Jörg Sommer
---
Completion/Linux/Command/_lsusb | 78 ++++++++++++++++++++++++++++-----------
1 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/Completion/Linux/Command/_lsusb b/Completion/Linux/Command/_lsusb
index 37701ac..3388f33 100644
--- a/Completion/Linux/Command/_lsusb
+++ b/Completion/Linux/Command/_lsusb
@@ -1,31 +1,65 @@
#compdef lsusb
-local context state line usbidsline vendorid pair
+local context state line
typeset -A opt_args
_arguments \
'(-v --verbose)'{-v,--verbose}'[be verbose]' \
- '-s:bus and/or devnum to show:' \
- '-d:vendor and product to show:->vendorproduct' \
- '-D:device to show:_files' \
+ '-s[Narrow to some devices]:bus and/or devnum to show:->bus_devnum' \
+ '-d:vendor and product to show:->vendor_product' \
+ '-D:device to show:_files -g "*(%)"' \
'-t[dump the physical USB device hierarchy as a tree]' \
- '(-V --version)'{-V,--version}'[print version info and exit]' && return 0
+ '(-)'{-V,--version}'[print version info and exit]' && return 0
- if [[ ${+_lsusb_vendors} -eq 0 ]]; then
- typeset -A _lsusb_vendors _lsusb_devices
- while IFS="" read usbidsline
- do
- case "$usbidsline" in
- ((#b)([0-9a-f]##) ##(*))
- vendorid="$match[1]"
- _lsusb_vendors[$vendorid]="$match[2]"
- ;;
- ( (#b)([0-9a-f]##) ##(*)))
- pair="$vendorid:$match[1]"
- _lsusb_devices[${pair}]="$match[2]"
- ;;
- esac
- done < <(zcat /var/lib/usbutils/usb.ids)
-fi
+case "$state" in
+ (bus_devnum)
+ local B bus D device I id descr bus_dev
+ _call_program usb_devices lsusb \
+ | while IFS=" " read -r B bus D device I id descr
+ do
+ if [[ $B$D$I != BusDeviceID ]]
+ then
+ echo "Internal error: Unknown lsusb output line:" \
+ "$B $bus $D $device $I $id $descr" >&2
+ else
+ bus_dev+=(${(M)bus%%[1-9]*}\\:${${(M)device%%[1-9]*}%:}:$descr)
+ fi
+ done
+ _describe -t usb_addresses 'usb device address' bus_dev
+ ;;
-compadd -k _lsusb_devices
+ (vendor_product)
+ if ! (( ${+_cache_lsusb_devices} ))
+ then
+ local id name last_vendor_id
+ while IFS=" " read -r id name
+ do
+ case "$id" in
+ (*\#*|)
+ ;;
+ (' '*)
+ # interface interface_name
+ ;;
+ (' '*)
+ # device_id device_name
+ _cache_lsusb_devices+=($last_vendor_id\\:${id# }:$name)
+ ;;
+ ([!0-9a-f]*)
+ # Here start other entries like classes (C) and languages (L)
+ break
+ ;;
+ (*)
+ last_vendor_id=$id
+ ;;
+ esac
+ done < /var/lib/usbutils/usb.ids
+ fi
+
+ _describe -t usb_device_ids 'usb device ids' _cache_lsusb_devices
+ ;;
+
+ (*)
+ echo "Internal error: Unknown state: $state" >&2
+ return 1
+ ;;
+esac
--
1.6.2.rc0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-02-27 14:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-27 10:18 [PATCH] New, extended completion for lsusb Jörg Sommer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).