From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17960 invoked from network); 27 Feb 2009 14:16:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 27 Feb 2009 14:16:59 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 19949 invoked from network); 27 Feb 2009 14:16:51 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Feb 2009 14:16:51 -0000 Received: (qmail 2407 invoked by alias); 27 Feb 2009 14:16:47 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26623 Received: (qmail 2394 invoked from network); 27 Feb 2009 14:16:47 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 27 Feb 2009 14:16:47 -0000 Received: from uucp.gnuu.de (uucp.gnuu.de [83.246.114.63]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5C77A8058F83 for ; Fri, 27 Feb 2009 15:16:43 +0100 (CET) Received: by uucp.gnuu.de (Postfix, from userid 10) id B7E7F488037; Fri, 27 Feb 2009 15:16:41 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.5.2 uucp.gnuu.de B7E7F488037 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=gnuu.de; s=banki; t=1235744201; i=@alea.gnuu.de; bh=wMEwGWMto4uV1Q0EW6jprsLqLcqS7WCDF gbz/th+XFk=; h=From:To:Cc:Subject:Date:Message-Id; b=NFxNgCWuk5eqVh HWrfyBtLF+kI7mK7zE4bxJ1mLF/2wCeBq8HUmr6Ei9PKimuQSsxGcl3dMoKobSjPi6X 58kkFGv2xS0OgYXKTwhw6Mp0mJDrTSZ9tC3SScOuKBu3mjH9ai4Flm63FGJC6le+RTD AZmHMX9+JqgUPum9wOzo+cE= Received: from ibook.localnet ([192.168.0.5] helo=alea.gnuu.de) by alea.gnuu.de with esmtp (Exim 4.69) (envelope-from ) id 1LcznC-0000r8-I0 for zsh-workers@sunsite.dk; Fri, 27 Feb 2009 11:18:06 +0100 Received: from joerg by alea.gnuu.de with local (Exim 4.69) (envelope-from ) id 1LcznC-0002sU-3J; Fri, 27 Feb 2009 11:18:06 +0100 From: =?utf-8?q?J=C3=B6rg=20Sommer?= To: zsh-workers@sunsite.dk Cc: =?utf-8?q?J=C3=B6rg=20Sommer?= Subject: [PATCH] New, extended completion for lsusb Date: Fri, 27 Feb 2009 11:18:06 +0100 Message-Id: <1235729886-11033-1-git-send-email-joerg@alea.gnuu.de> X-Mailer: git-send-email 1.6.2.rc0 X-Virus-Scanned: ClamAV 0.92.1/9054/Fri Feb 27 10:02:52 2009 on bifrost X-Virus-Status: Clean --- 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