From 8c7c094558fa998ad41d68e5410e896da52a580f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Mon, 8 Aug 2016 19:26:53 +0200 Subject: [PATCH 1/7] Autogenerated the easy parts --- src/_lsblk | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/_lsblk diff --git a/src/_lsblk b/src/_lsblk new file mode 100644 index 0000000..1e2b5b3 --- /dev/null +++ b/src/_lsblk @@ -0,0 +1,34 @@ +#compdef lsblk + +# zsh completions for 'lsblk' +# automatically generated with http://github.com/RobSis/zsh-completion-generator +local arguments + +arguments=( + {-a,--all}'[print all devices]' + {-b,--bytes}'[print SIZE in bytes rather than in human readable format]' + {-d,--nodeps}'[dont print slaves or holders]' + {-D,--discard}'[print discard capabilities]' + {-e,--exclude}'[exclude devices by major number (default: RAM disks)]' + {-f,--fs}'[output info about filesystems]' + {-i,--ascii}'[use ascii characters only]' + {-I,--include}'[show only devices with specified major numbers]' + {-J,--json}'[use JSON output format]' + {-l,--list}'[use list format output]' + {-m,--perms}'[output info about permissions]' + {-n,--noheadings}'[dont print headings]' + {-o,--output}'[output columns]' + {-O,--output-all}'[output all columns]' + {-p,--paths}'[print complete device path]' + {-P,--pairs}'[use key="value" output format]' + {-r,--raw}'[use raw output format]' + {-s,--inverse}'[inverse dependencies]' + {-S,--scsi}'[output info about SCSI devices]' + {-t,--topology}'[output info about topology]' + {-x,--sort}'[sort output by ]' + {-h,--help}'[display this help and exit]' + {-V,--version}'[output version information and exit]' + '*:filename:_files' +) + +_arguments -s $arguments From 99713ff544c49cbe829541620fe9bdaea400d1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Mon, 8 Aug 2016 19:30:36 +0200 Subject: [PATCH 2/7] Minor adjustments to the descriptions --- src/_lsblk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index 1e2b5b3..250e425 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -6,7 +6,7 @@ local arguments arguments=( {-a,--all}'[print all devices]' - {-b,--bytes}'[print SIZE in bytes rather than in human readable format]' + {-b,--bytes}'[print size in bytes rather than in human readable format]' {-d,--nodeps}'[dont print slaves or holders]' {-D,--discard}'[print discard capabilities]' {-e,--exclude}'[exclude devices by major number (default: RAM disks)]' @@ -17,7 +17,7 @@ arguments=( {-l,--list}'[use list format output]' {-m,--perms}'[output info about permissions]' {-n,--noheadings}'[dont print headings]' - {-o,--output}'[output columns]' + {-o,--output}'[specify output columns]' {-O,--output-all}'[output all columns]' {-p,--paths}'[print complete device path]' {-P,--pairs}'[use key="value" output format]' @@ -25,7 +25,7 @@ arguments=( {-s,--inverse}'[inverse dependencies]' {-S,--scsi}'[output info about SCSI devices]' {-t,--topology}'[output info about topology]' - {-x,--sort}'[sort output by ]' + {-x,--sort}'[sort output by specified column]' {-h,--help}'[display this help and exit]' {-V,--version}'[output version information and exit]' '*:filename:_files' From 80bee25a20985c581cc23adb104789f74616bf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Mon, 8 Aug 2016 19:54:39 +0200 Subject: [PATCH 3/7] Don't suggest same option twice --- src/_lsblk | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index 250e425..826f036 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -4,30 +4,31 @@ # automatically generated with http://github.com/RobSis/zsh-completion-generator local arguments + arguments=( - {-a,--all}'[print all devices]' - {-b,--bytes}'[print size in bytes rather than in human readable format]' - {-d,--nodeps}'[dont print slaves or holders]' - {-D,--discard}'[print discard capabilities]' - {-e,--exclude}'[exclude devices by major number (default: RAM disks)]' - {-f,--fs}'[output info about filesystems]' - {-i,--ascii}'[use ascii characters only]' - {-I,--include}'[show only devices with specified major numbers]' - {-J,--json}'[use JSON output format]' - {-l,--list}'[use list format output]' - {-m,--perms}'[output info about permissions]' - {-n,--noheadings}'[dont print headings]' - {-o,--output}'[specify output columns]' - {-O,--output-all}'[output all columns]' - {-p,--paths}'[print complete device path]' - {-P,--pairs}'[use key="value" output format]' - {-r,--raw}'[use raw output format]' - {-s,--inverse}'[inverse dependencies]' - {-S,--scsi}'[output info about SCSI devices]' - {-t,--topology}'[output info about topology]' - {-x,--sort}'[sort output by specified column]' - {-h,--help}'[display this help and exit]' - {-V,--version}'[output version information and exit]' + '(-a --all)'{-a,--all}'[print all devices]' + '(-b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' + '(-d --nodeps)'{-d,--nodeps}'[dont print slaves or holders]' + '(-D --discard)'{-D,--discard}'[print discard capabilities]' + '(-e --exclude)'{-e,--exclude}'[exclude devices by major number (default: RAM disks)]' + '(-f --fs)'{-f,--fs}'[output info about filesystems]' + '(-i --ascii)'{-i,--ascii}'[use ascii characters only]' + '(-I --include)'{-I,--include}'[show only devices with specified major numbers]' + '(-J --json)'{-J,--json}'[use JSON output format]' + '(-l --list)'{-l,--list}'[use list format output]' + '(-m --perms)'{-m,--perms}'[output info about permissions]' + '(-n --noheadings)'{-n,--noheadings}'[dont print headings]' + '(-o --output)'{-o,--output}'[specify output columns]' + '(-O --output-all)'{-O,--output-all}'[output all columns]' + '(-p --paths)'{-p,--paths}'[print complete device path]' + '(-P --pairs)'{-P,--pairs}'[use key="value" output format]' + '(-r --raw)'{-r,--raw}'[use raw output format]' + '(-s --inverse)'{-s,--inverse}'[inverse dependencies]' + '(-S --scsi)'{-S,--scsi}'[output info about SCSI devices]' + '(-t --topology)'{-t,--topology}'[output info about topology]' + '(-x --sort)'{-x,--sort}'[sort output by specified column]' + '(-h --help)'{-h,--help}'[display this help and exit]' + '(-V --version)'{-V,--version}'[output version information and exit]' '*:filename:_files' ) From db301d4b32e4374ffd73a78f59314a0a789841ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Mon, 8 Aug 2016 20:56:26 +0200 Subject: [PATCH 4/7] Complete output column names --- src/_lsblk | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index 826f036..46c0646 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -5,6 +5,21 @@ local arguments +local LSBLK_COLS_ALL=( + NAME KNAME MAJ:MIN FSTYPE MOUNTPOINT + LABEL UUID PARTTYPE PARTLABEL PARTUUID PARTFLAGS + RA RO RM + MODEL SIZE STATE OWNER GROUP MODE + ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC + ROTA SCHED RQ-SIZE TYPE DISC-ALN + DISC-GRAN DISC-MAX DISC-ZERO WSAME WWN + RAND PKNAME HCTL TRAN REV VENDOR) + +_lsblk_columns() { + compadd $@ $LSBLK_COLS_ALL +} + + arguments=( '(-a --all)'{-a,--all}'[print all devices]' '(-b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' @@ -18,7 +33,7 @@ arguments=( '(-l --list)'{-l,--list}'[use list format output]' '(-m --perms)'{-m,--perms}'[output info about permissions]' '(-n --noheadings)'{-n,--noheadings}'[dont print headings]' - '(-o --output)'{-o,--output}'[specify output columns]' + '(-o --output)'{-o,--output}'=[specify output columns]:Output columns:_sequence _lsblk_columns' '(-O --output-all)'{-O,--output-all}'[output all columns]' '(-p --paths)'{-p,--paths}'[print complete device path]' '(-P --pairs)'{-P,--pairs}'[use key="value" output format]' @@ -26,7 +41,7 @@ arguments=( '(-s --inverse)'{-s,--inverse}'[inverse dependencies]' '(-S --scsi)'{-S,--scsi}'[output info about SCSI devices]' '(-t --topology)'{-t,--topology}'[output info about topology]' - '(-x --sort)'{-x,--sort}'[sort output by specified column]' + '(-x --sort)'{-x,--sort}'=[sort output by specified column]:Sort column:_lsblk_columns' '(-h --help)'{-h,--help}'[display this help and exit]' '(-V --version)'{-V,--version}'[output version information and exit]' '*:filename:_files' From 1ecc42490edabc207bcdad2efb91225a094d0620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 9 Aug 2016 17:21:36 +0200 Subject: [PATCH 5/7] Only complete device files (and directories) + Some cleanup --- src/_lsblk | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index 46c0646..f1d6718 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -1,11 +1,8 @@ #compdef lsblk -# zsh completions for 'lsblk' -# automatically generated with http://github.com/RobSis/zsh-completion-generator local arguments - -local LSBLK_COLS_ALL=( +local lsblk_cols_all=( NAME KNAME MAJ:MIN FSTYPE MOUNTPOINT LABEL UUID PARTTYPE PARTLABEL PARTUUID PARTFLAGS RA RO RM @@ -16,10 +13,9 @@ local LSBLK_COLS_ALL=( RAND PKNAME HCTL TRAN REV VENDOR) _lsblk_columns() { - compadd $@ $LSBLK_COLS_ALL + compadd $@ $lsblk_cols_all } - arguments=( '(-a --all)'{-a,--all}'[print all devices]' '(-b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' @@ -44,7 +40,7 @@ arguments=( '(-x --sort)'{-x,--sort}'=[sort output by specified column]:Sort column:_lsblk_columns' '(-h --help)'{-h,--help}'[display this help and exit]' '(-V --version)'{-V,--version}'[output version information and exit]' - '*:filename:_files' + '*:device:_path_files -g "*(N-%) *(N-/)"' ) _arguments -s $arguments From fc617458c154013fa1b021d1330b1ef4a3d313b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 9 Aug 2016 17:40:44 +0200 Subject: [PATCH 6/7] Complete major numbers too (--include/--exclude) --- src/_lsblk | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index f1d6718..59a3ff9 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -16,15 +16,23 @@ _lsblk_columns() { compadd $@ $lsblk_cols_all } +_lsblk_major_number() { + # /sys/dev/block/ contains MAJOR:MINOR symlinks. eg. 7:0 + local device_paths=(/sys/dev/block/*(N)) + local major_numbers=(${${device_paths##*/}%%:*}) + # major_numbers might have duplicates but compadd handles that + compadd $@ $major_numbers +} + arguments=( '(-a --all)'{-a,--all}'[print all devices]' '(-b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' '(-d --nodeps)'{-d,--nodeps}'[dont print slaves or holders]' '(-D --discard)'{-D,--discard}'[print discard capabilities]' - '(-e --exclude)'{-e,--exclude}'[exclude devices by major number (default: RAM disks)]' + '(-e --exclude)'{-e,--exclude}'[exclude devices by major number (default: RAM disks)]:major number:_sequence _lsblk_major_number' '(-f --fs)'{-f,--fs}'[output info about filesystems]' '(-i --ascii)'{-i,--ascii}'[use ascii characters only]' - '(-I --include)'{-I,--include}'[show only devices with specified major numbers]' + '(-I --include)'{-I,--include}'=[show only devices with specified major numbers]:major number:_sequence _lsblk_major_number' '(-J --json)'{-J,--json}'[use JSON output format]' '(-l --list)'{-l,--list}'[use list format output]' '(-m --perms)'{-m,--perms}'[output info about permissions]' From 3c7788c90977ec850621040c4a87b7af1bb1543d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 9 Aug 2016 17:44:38 +0200 Subject: [PATCH 7/7] Add header (copyright, etc) and some description adjustments - Comply with zsh/Etc/completion-style-guide - Comply with zsh-completions contribution guidelines --- src/_lsblk | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/_lsblk b/src/_lsblk index 59a3ff9..4040338 100644 --- a/src/_lsblk +++ b/src/_lsblk @@ -1,4 +1,47 @@ #compdef lsblk +# ------------------------------------------------------------------------------ +# Copyright (c) 2016 Github zsh-users - http://github.com/zsh-users +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the zsh-users nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for lsblk (from util-linux 2.27.1->) +# (https://git.kernel.org/cgit/utils/util-linux/util-linux.git/) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Ole Jørgen Brønner +# +# ------------------------------------------------------------------------------ +# +# Note: lsblk has upstream bash completions, which has served as a guide +# Note: Credit to https://github.com/RobSis/zsh-completion-generator which was +# used to generate an initial skeleton local arguments @@ -29,7 +72,7 @@ arguments=( '(-b --bytes)'{-b,--bytes}'[print size in bytes rather than in human readable format]' '(-d --nodeps)'{-d,--nodeps}'[dont print slaves or holders]' '(-D --discard)'{-D,--discard}'[print discard capabilities]' - '(-e --exclude)'{-e,--exclude}'[exclude devices by major number (default: RAM disks)]:major number:_sequence _lsblk_major_number' + '(-e --exclude)'{-e,--exclude}'[exclude devices by major number]:major number:_sequence _lsblk_major_number' '(-f --fs)'{-f,--fs}'[output info about filesystems]' '(-i --ascii)'{-i,--ascii}'[use ascii characters only]' '(-I --include)'{-I,--include}'=[show only devices with specified major numbers]:major number:_sequence _lsblk_major_number' @@ -37,7 +80,7 @@ arguments=( '(-l --list)'{-l,--list}'[use list format output]' '(-m --perms)'{-m,--perms}'[output info about permissions]' '(-n --noheadings)'{-n,--noheadings}'[dont print headings]' - '(-o --output)'{-o,--output}'=[specify output columns]:Output columns:_sequence _lsblk_columns' + '(-o --output)'{-o,--output}'=[specify output columns]:output column:_sequence _lsblk_columns' '(-O --output-all)'{-O,--output-all}'[output all columns]' '(-p --paths)'{-p,--paths}'[print complete device path]' '(-P --pairs)'{-P,--pairs}'[use key="value" output format]' @@ -45,7 +88,7 @@ arguments=( '(-s --inverse)'{-s,--inverse}'[inverse dependencies]' '(-S --scsi)'{-S,--scsi}'[output info about SCSI devices]' '(-t --topology)'{-t,--topology}'[output info about topology]' - '(-x --sort)'{-x,--sort}'=[sort output by specified column]:Sort column:_lsblk_columns' + '(-x --sort)'{-x,--sort}'=[sort output by specified column]:sort column:_lsblk_columns' '(-h --help)'{-h,--help}'[display this help and exit]' '(-V --version)'{-V,--version}'[output version information and exit]' '*:device:_path_files -g "*(N-%) *(N-/)"'