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

This makes use of the new groups to keep the exclusion lists shorter
than they might otherwise be.

lsblk is a util-linux tool for listing block devices.

Oliver

diff --git a/Completion/Linux/Command/_lsblk b/Completion/Linux/Command/_lsblk
new file mode 100644
index 000000000..e1863cd06
--- /dev/null
+++ b/Completion/Linux/Command/_lsblk
@@ -0,0 +1,57 @@
+#compdef lsblk
+
+local sep ret=1
+local -a values dedup suf=( -qS , )
+local curcontext="$curcontext" state line expl
+typeset -A opt_args
+
+_arguments -C -s -S \
+  '(H -a --all)'{-a,--all}'[print all devices]' \
+  '(H -b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' \
+  '(H -d --nodeps)'{-d,--nodeps}"[don't print slaves or holders]" \
+  '(H -I --include)*'{-e,--exclude}'[exclude devices by major number]:major device number:->majorlist' \
+  '(H -e --exclude)*'{-I+,--include=}'[show only devices with specified major numbers]:major device number:->majorlist' \
+  '(H -n --noheadings)'{-n,--noheadings}"[don't print headings]" \
+  '(H -p --paths)'{-p,--paths}'[print complete device path]' \
+  '(H -s --inverse)'{-s,--inverse}'[reverse dependency order]' \
+  '(H -x --sort)'{-x+,--sort=}'[sort output by specified column]:column:->columns' \
+  '*:device:_files -g "*(-%b)" -P / -W /' \
+  + fields \
+  '(H -D --discard -o --output -O --output-all)'{-D,--discard}'[output discard capabilities]' \
+  '(H -f --fs -o --output -O --output-all)'{-f,--fs}'[output info about filesystems]' \
+  '(H -m --perms -o --output -O --output-all)'{-m,--perms}'[output info about permissions]' \
+  '(H -S --scsi -o --output -O --output-all)'{-S,--scsi}'[output info about SCSI devices]' \
+  '(H -t --topology -o --output -O --output-all)'{-t,--topology}'[output info about topology]' \
+  '(H fields)'{-o+,--output=}'[specify output columns]:output column:->columnlist' \
+  '(H fields)'{-O,--output-all}'[output all columns]' \
+  + '(format)' \
+  '(H)'{-i,--ascii}'[output ascii characters only]' \
+  '(H)'{-J,--json}'[use JSON output format]' \
+  '(H)'{-l,--list}'[use list format output]' \
+  '(H)'{-P,--pairs}'[use key="value" output format]' \
+  '(H)'{-r,--raw}'[use raw output format]' \
+  + 'H' \
+  '(* -)'{-h,--help}'[display help information]' \
+  '(* -)'{-V,--version}'[display version information]' && ret=0
+
+case $state in
+  *list)
+    dedup=( ${(Ms.,.)PREFIX##*,} ${(Ms.,.)SUFFIX%%,*} )
+    compset -S ',*' && suf=()
+    compset -P '*,'
+  ;|
+  column*)
+    values=(
+      ${${${${(f)"$(_call_program columns lsblk -h)"}[(r)Available*,-3]## #}[2,-1]//:/\\:}/  /:}
+    )
+    _describe -t fields column values -M 'm:{a-z}={A-Z}' $suf -F dedup && ret=0
+  ;;
+  major*)
+    zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+    values=( ${${${(f)"$(</proc/devices)"}[(r)Block*,-1]## #}[2,-1]/ /:} )
+    zformat -a values " $sep " $values
+    _wanted -V devices expl 'major device number' compadd $suf -d values -F dedup ${values%% *} && ret=0
+  ;;
+esac
+
+return ret


                 reply	other threads:[~2017-01-12 23:22 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=23884.1484262954@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).