Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] New, extended completion for lsusb
- X-seq: zsh-workers 26623
- From: JÃrg Sommer <joerg@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: [PATCH] New, extended completion for lsusb
- Date: Fri, 27 Feb 2009 11:18:06 +0100
- Cc: JÃrg Sommer <joerg@xxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=gnuu.de; s=banki; t=1235744201; i=@xxxxxxxxxxxx; bh=wMEwGWMto4uV1Q0EW6jprsLqLcqS7WCDF gbz/th+XFk=; h=From:To:Cc:Subject:Date:Message-Id; b=NFxNgCWuk5eqVh HWrfyBtLF+kI7mK7zE4bxJ1mLF/2wCeBq8HUmr6Ei9PKimuQSsxGcl3dMoKobSjPi6X 58kkFGv2xS0OgYXKTwhw6Mp0mJDrTSZ9tC3SScOuKBu3mjH9ai4Flm63FGJC6le+RTD AZmHMX9+JqgUPum9wOzo+cE=
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
---
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author