zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: lsusb completion update
Date: Fri, 13 Jan 2017 01:16:30 +0100	[thread overview]
Message-ID: <55473.1484266590@hydra.kiddle.eu> (raw)

After adding _lsblk, I noticed _lsusb an a quick check showed it was only
really missing --tree. I also added some exclusions and descriptions and
the usb.ids file is in a different path on my system. I'm not sure
completing all IDs is particularly useful but whatever.

Oliver

diff --git a/Completion/Linux/Command/_lsusb b/Completion/Linux/Command/_lsusb
index 17240e03d..1807f5e93 100644
--- a/Completion/Linux/Command/_lsusb
+++ b/Completion/Linux/Command/_lsusb
@@ -1,19 +1,21 @@
 #compdef lsusb
 
-local context state line usbidsline vendorid pair
+local usbidsline vendorid pair ret=1
+local curcontext="$curcontext" state line expl
 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' \
-  '-t[dump the physical USB device hierarchy as a tree]' \
-  '(-V --version)'{-V,--version}'[print version info and exit]' && return 0
+_arguments -C \
+  '(-v --verbose -t --tree)'{-v,--verbose}'[be verbose]' \
+  '-s+[filter devices by bus and/or device number]:bus and/or devnum to show' \
+  '-d+[filter devices by vendor/product ID]:vendor and product to show:->vendorproduct' \
+  '-D+[display only specified device]:device:_files -g "*(-%)" -P / -W /' \
+  '(-t --tree -v --verbose)'{-t,--tree}'[dump the physical USB device hierarchy as a tree]' \
+  '(-)'{-V,--version}'[print version information]' \
+  '(-)'{-h,--help}'[print help information]' && ret=0
 
-  if [[ ${+_lsusb_vendors} -eq 0 ]]; then
-    typeset -A _lsusb_vendors _lsusb_devices
-  while IFS="" read usbidsline
+if [[ -n $state && ${+_lsusb_vendors} -eq 0 ]]; then
+  typeset -A _lsusb_vendors _lsusb_devices
+  cat /usr/share/(misc|hwdata)/usb.ids | while IFS="" read usbidsline
   do
     case "$usbidsline" in
       ((#b)([0-9a-f]##) ##(*))
@@ -25,7 +27,9 @@ _arguments \
         _lsusb_devices[${pair}]="$match[2]"
       ;;
     esac
-  done < /usr/share/misc/usb.ids
+  done
 fi
 
-compadd -k _lsusb_devices
+_wanted vendors:products expl 'vendor ID:product ID' compadd -k _lsusb_devices && ret=0
+
+return ret


                 reply	other threads:[~2017-01-13  0:44 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=55473.1484266590@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /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).