From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id ea7271bf for ; Mon, 8 Apr 2019 10:27:36 +0000 (UTC) Received: (qmail 23342 invoked by alias); 8 Apr 2019 10:27:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44210 Received: (qmail 21338 invoked by uid 1010); 8 Apr 2019 10:27:19 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-expgw.biglobe.ne.jp by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25412. spamassassin: 3.4.2. Clear:RC:0(133.208.98.3):SA:0(-2.6/5.0):. Processed in 1.524933 secs); 08 Apr 2019 10:27:19 -0000 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spf01.biglobe.ne.jp designates 133.208.98.3 as permitted sender) X-Biglobe-Sender: From: Jun T Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: [PATCH] new completion for findmnt Message-Id: <30C02DDE-FE58-45C5-8FEC-CB9536194B27@kba.biglobe.ne.jp> Date: Mon, 8 Apr 2019 19:26:40 +0900 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3445.104.8) X-Biglobe-Spnum: 61514 New completion for findmnt. _lsblk is also slightly updated. Both are based on util-linux 2.32.1. diff --git a/Completion/Linux/Command/_findmnt = b/Completion/Linux/Command/_findmnt new file mode 100644 index 000000000..06393437a --- /dev/null +++ b/Completion/Linux/Command/_findmnt @@ -0,0 +1,114 @@ +#compdef findmnt +# +# Note for customization: +# Options -N -k -m -s are in a group 'S' and need be specified as +# 'S-option-N' etc. in the context for zstyle. For example, if you = want +# all PIDs to be completed for 'findmnt -N', then +# zstyle ':completion:*:findmnt:S-option-N-1:processes' command 'ps = -A' +# +local curcontext=3D$curcontext state state_descr line ret=3D1 +typeset -A opt_args + +_arguments -s -C \ + '(H -A --all)'{-A,--all}'[print all filesystems]' \ + '(H -a --ascii)'{-a,--ascii}'[use ascii characters for tree = formatting]' \ + '(H -b --bytes)'{-b,--bytes}'[print SIZE etc. in bytes]' \ + '(H -c --nocanonicalize)'{-c,--nocanonicalize}'[do not canonicalize = path]' \ + '(H -d --direction)'{-d+,--direction=3D}'[specify the search = direction]:direction:(forward backward)' \ + '(H -e --evaluate)'{-e,--evaluate}'[convert = LABEL/UUID/PARTLABEL/PARTUUID to the device name]' \ + '(H -F --tab-file)*'{-F+,--tab-file=3D}'[search in the specified tab = file]:tab file:_files' \ + '(H -f --first-only)'{-f,--first-only}'[print the first matching = filesystem only]' \ + '(H -i --invert)'{-i,--invert}'[invert the sense of matching]' \ + '(H -M --mountpoint :)'{-M+,--mountpoint=3D}'[specify the = mountpoint]: :->targets' \ + '(H -n --noheadings)'{-n,--noheadings}'[do not print a header line]' = \ + '(H -O --options)'{-O+,--options=3D}'[only print the filesystems with = the specified options]:list of options: ' \ + '(H -o --output)'{-o+,--output=3D}'[specify output columns]: = :->columns' \ + '(H -p --poll)'{-p+,--poll=3D}'[monitor changes in = /proc/self/mountinfo]::action:(mount umount remount move)' \ + '(H -R --submounts)'{-R,--submounts}'[print recursively all = submounts]' \ + '(H -S --source :)'{-S+,--source=3D}'[specify the mount source]: = :->sources' \ + '(H -T --target :)'{-T+,--target=3D}'[specify the mount = target]:target:_files' \ + '(H -t --types)'{-t+,--types=3D}'[specify the type of = filesystems]:filesystem types:_sequence -s , _file_systems' \ + '--tree[use tree-like output if possible]' \ + '(H -U --uniq)'{-U,--uniq}'[ignore filesystems with duplicated mount = targets]' \ + '(H -u --notruncate)'{-u,--notruncate}'[do not truncate text in = columns]' \ + '(H -v --nofsroot)'{-v,--nofsroot}'[do not print \[/dir\] in the = SOURCE column]' \ + '(H -w --timeout)'{-w+,--timeout}'[specify timeout for = --poll]:miliseconds: ' \ + '(H -x --verify)'{-x,--verify}'[check mount table content]' \ + '(H)--verbose[print more information]' \ + '(H)1: :->sources_targets' \ + '(H)2:: :->targets' \ + + '(format)' \ + '(H)'{-D,--df}'[imitate the output of df command]' \ + '(H)'{-J,--json}'[use JASON output format]' \ + '(H)'{-l,--list}'[use list output format]' \ + '(H)'{-P,--pairs}'[use key=3D"value" output format]' \ + '(H)'{-r,--raw}'[use raw output format]' \ + + '(S)' \ + '(H)'{-k,--kernel}'[search in /proc/self/mountinfo (default)]' \ + '(H)'{-m,--mtab}'[search in /etc/mtab]' \ + '(H)'{-N+,--task=3D}'[search /proc//mountinfo]: :_pids' \ + '(H)'{-s,--fstab}'[search in /etc/fstab]' \ + + '(H)' \ + '(- :)'{-h,--help}'[display help text and exit]' \ + '(- :)'{-V,--version}'[display version and exit]' \ + && ret=3D0 + +__findmnt_mountpoints () { + compadd "$@" \ + ${(f)"$(_call_program mount-points findmnt $opts -oTARGET)"} +} + +case $state in + columns) + compset -P '+' || _describe -t list-prefixes prefix \ + '( +:"not replace but extend the list" )' -S '' && = ret=3D0 + local -a columns=3D( + ${${${(f)"$(_call_program columns findmnt = -h)"}[(r)Available*,-2]}[2,-1]} + ) + columns=3D( ${${${${${${columns## #}//:/\\:}//\[/\\[}//]/\\]}/ = /[}/%/]} ) + _values -s , -M 'm:{a-z}=3D{A-Z}' column $columns && ret=3D0 + ;; + *) # call "findmnt $opts" to get possible sources/targets + local opts=3D'-lnve' + if [[ -n $opt_args[(I)S-(-m|--mtab)] ]]; then + opts+=3D' -m' + elif [[ -n $opt_args[(I)S-(-s|--fstab)] ]]; then + opts+=3D' -s' + elif [[ -n $opt_args[(I)S-(-N|--task)] ]]; then + opts+=3D" -N${(v)opt_args[(I)S-(-N|--task)]}" + fi + ;| + sources*) # 'sources' or 'sources_targets' + local -a val + if compset -P 'LABEL=3D'; then + val=3D( ${(f)"$(_call_program labels findmnt $opts -oLABEL)"} ) + _describe -t labels 'LABEL' val && ret=3D0 + elif compset -P 'PARTLABEL=3D'; then + val=3D( ${(f)"$(_call_program labels findmnt $opts -oPARTLABEL)"} = ) + _describe -t labels 'PARTLABEL' val && ret=3D0 + elif compset -P 'UUID=3D'; then + val=3D( ${(f)"$(_call_program uuids findmnt $opts -oUUID)"} ) + _describe -t uuids 'UUID' val && ret=3D0 + elif compset -P 'PARTUUID=3D'; then + val=3D( ${(f)"$(_call_program uuids findmnt $opts -oPARTUUID)"} ) + _describe -t uuids 'PARTUUID' val && ret=3D0 + else + local -a alts=3D( + 'devices:device:compadd \ + $(_call_program devices findmnt $opts -oSOURCE)' + 'device-numbers:major-minor:compadd \ + ${$(_call_program device-numbers findmnt $opts = -oMAJ:MIN)// /}' + 'prefixes:prefix:compadd -S "" LABEL=3D UUID=3D PARTLABEL=3D = PARTUUID=3D' + ) + [[ $state =3D sources_targets ]] && + alts+=3D( 'mount-points:moutpoint:__findmnt_mountpoints' ) + _alternative $alts && ret=3D0 + fi + ;; + targets) + local expl + _wanted mount-points expl 'mountpoint' __findmnt_mountpoints && = ret=3D0 + ;; +esac + +return ret diff --git a/Completion/Linux/Command/_lsblk = b/Completion/Linux/Command/_lsblk index 1a3687c45..a95ebe776 100644 --- a/Completion/Linux/Command/_lsblk +++ b/Completion/Linux/Command/_lsblk @@ -38,6 +38,10 @@ _arguments -C -s -S \ '(* -)'{-V,--version}'[display version information]' && ret=3D0 =20 case $state in + columnlist) + compset -P '+' || _describe -t list-prefixes prefix \ + '( +:"not replace but extend the list" )' -S '' && = ret=3D0 + ;| *list) dedup=3D( ${(Ms.,.)PREFIX##*,} ${(Ms.,.)SUFFIX%%,*} ) compset -S ',*' && suf=3D() @@ -45,7 +49,7 @@ case $state in ;| column*) values=3D( - ${${${${(f)"$(_call_program columns lsblk = -h)"}[(r)Available*,-3]## #}[2,-1]//:/\\:}/ /:} + ${${${${(f)"$(_call_program columns lsblk = -h)"}[(r)Available*,-2]## #}[2,-1]//:/\\:}/ /:} ) _describe -t fields column values -M 'm:{a-z}=3D{A-Z}' $suf -F = dedup && ret=3D0 ;;