From: "Jörg Sommer" <joerg@alea.gnuu.de>
To: zsh-workers@sunsite.dk
Cc: "Jörg Sommer" <joerg@alea.gnuu.de>
Subject: [PATCH] New, extended completion for lsusb
Date: Fri, 27 Feb 2009 11:18:06 +0100 [thread overview]
Message-ID: <1235729886-11033-1-git-send-email-joerg@alea.gnuu.de> (raw)
---
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
reply other threads:[~2009-02-27 14:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1235729886-11033-1-git-send-email-joerg@alea.gnuu.de \
--to=joerg@alea.gnuu.de \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).