From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27227 invoked by alias); 2 Aug 2017 15:10:17 -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: X-Seq: 41481 Received: (qmail 9544 invoked from network); 2 Aug 2017 15:10:17 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-0.7/5.0):. Processed in 2.354065 secs); 02 Aug 2017 15:10:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=0T3VWY zBDikQmmlyIUqRUaPkbQ7UkBExh6UBIjIdXKs=; b=r4w1E4Etv2m9LDTjEoueez rL8pFye9CgYSNp0Z/8gbrUENcTaFQ4TRcEHNEEnurisVkvvzQEXq0TsIjEMYJ8SY SOLcTWRKoNTgRDfXEymsRLIMqpq5qYuG4BzHR7L0Aezc1Ym9obbfihYObQ+NZFhL epmqtwwBcU7NNBfzfGoP7JJiyBdyrGsZwTs6nhYjPTANIB0ykKX7qi2KNmGuL1yH O9r8acX1iLHJHOw+/9Msu3Fm3QcY+qU+ctzU361wq4ZurFd4ZFhsrMBhDdkMh21/ vLNArsLEqa1WBgeqRV3kI5WmbpJsgKMTBC6OSLS8O5L+0NOmW5AupUfNfff90zSg == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=0T3VWY zBDikQmmlyIUqRUaPkbQ7UkBExh6UBIjIdXKs=; b=lgrvuiEGzer+jFfHg3QwZs k/Pn7/foTsbMEFrmrSL7P4WaMsNMHkAxFeZAuNLp509yCTdf7CogWNJhr/xBcPub L7T4ZfHYysFuV1JGyqfR8MZxW5QhJYTcOwjTn5ziLKkjsKg3zaPsZwL9vrx4JLLG Mdc4WWTU/vniPZcSJmza2o6c9oqsLfdDTxieNdchV4t8RX/ZL4cvrtjjSBFNqwZn znrVv/dzntVIwoS8LcetkGnJ5SuvLAQxpNGLFPUBpZTsalGtDPg9BVMg5MWpo2cv lHzT/gQKZjdkBFxBfa2BixvLRcuzN/rhUfeTGpGome0CIANXr2kbyXbn1gCnt7nw == X-ME-Sender: X-Sasl-enc: fbBxG58e8Qr6+2BzKotYreIcht/DSCZASN/MoMhelv8O 1501686605 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] _df: Complete mounted device and mount points. Date: Wed, 2 Aug 2017 15:10:02 +0000 Message-Id: <20170802151002.17288-1-danielsh@tarpaulin.shahaf.local2> X-Mailer: git-send-email 2.11.0 This splits umount's "udevordir" completion from _mount to a new file, without changing it. --- I tested this on linux, but both _df and _umountable have different codepaths for each of linux / BSD / other, so some testing on those would be appreciated. Cheers, Daniel Completion/Unix/Command/_df | 6 +++--- Completion/Unix/Command/_mount | 43 +-------------------------------------- Completion/Unix/Type/_umountable | 44 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 Completion/Unix/Type/_umountable diff --git a/Completion/Unix/Command/_df b/Completion/Unix/Command/_df index 677b8c727..d20ddea7e 100644 --- a/Completion/Unix/Command/_df +++ b/Completion/Unix/Command/_df @@ -16,7 +16,7 @@ if _pick_variant gnu=GNU unix --version; then '-v[(ignored)]' '(- : *)--help[display help and exit]' '(- : *)--version[output version information and exit]' - '*:files:_files' + '*:files:_umountable' - '(format)' {-B+,--block-size=}'[specify block size]:size (bytes)' '-k[like --block-size=1K]' @@ -39,7 +39,7 @@ elif [[ "$OSTYPE" == (darwin|freebsd|dragonfly)* ]]; then '-i[include inode usage statistics (default)]' '-l[only display locally-mounted file systems]' '-n[use previously obtained statistics]' - '*:files:_files' + '*:files:_umountable' ) spec='[only display file systems of specified types]:file system type:->fslist' case "$OSTYPE" in @@ -59,7 +59,7 @@ else '-k[use 1024-byte blocks]' '-P[POSIX compliant output]' '-t[include total allocated-space figures in the output]' - '*:files:_files' + '*:files:_umountable' ) fi diff --git a/Completion/Unix/Command/_mount b/Completion/Unix/Command/_mount index 9a7041dee..03cc01f8d 100644 --- a/Completion/Unix/Command/_mount +++ b/Completion/Unix/Command/_mount @@ -931,48 +931,7 @@ devordir) esac ;; udevordir) - local dev_tmp dpath_tmp mp_tmp mline - - case "$OSTYPE" in - linux*|irix*) - tmp=( "${(@f)$(< /etc/mtab)}" ) - dev_tmp=( "${(@)${(@)tmp%% *}:#none}" ) - mp_tmp=( "${(@)${(@)tmp#* }%% *}" ) - ;; - freebsd*|dragonfly*) - /sbin/mount | while read mline; do - dev_tmp+=( $mline[(w)1] ) - mp_tmp+=( $mline[(w)3] ) - done - ;; - darwin*) - tmp=( "${(@f)$(/sbin/mount)}" ) - dev_tmp=( "${(@)${(@)tmp%% *}:#map}" ) - mp_tmp=( "${(@)${(@)tmp#* on }%% \(*}" ) - ;; - *) - /sbin/mount | while read mline; do - mp_tmp+=( $mline[(w)1] ) - dev_tmp+=( $mline[(w)3] ) - done - ;; - esac - - local MATCH MBEGIN MEND - # The complicated substitution for mount point names is required because - # characters in /etc/mtab that might confuse programs reading the names - # are encoded as exactly 3 octal digits, like for example \040 for space. - # The cleaner-looking ${(g::)mp_tmp} might consume too many digits. - # Both mp_tmp and dev_tmp are derived from /etc/mtab or "mount" output. - mp_tmp=("${(@)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}") - dev_tmp=("${(@)dev_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}") - dpath_tmp=( "${(@M)dev_tmp:#/*}" ) - dev_tmp=( "${(@)dev_tmp:#/*}" ) - - _alternative \ - 'device-labels:device label:compadd -a dev_tmp' \ - 'device-paths: device path:_canonical_paths -A dpath_tmp -N -M "r:|/=* r:|=*" device-paths device\ path' \ - 'directories:mount point:_canonical_paths -A mp_tmp -N -M "r:|/=* r:|=*" directories mount\ point' && ret=0 + _umountable ;; labels) _wanted labels expl 'disk label' compadd /dev/disk/by-label/*(:t) && ret=0 diff --git a/Completion/Unix/Type/_umountable b/Completion/Unix/Type/_umountable new file mode 100644 index 000000000..2b2567478 --- /dev/null +++ b/Completion/Unix/Type/_umountable @@ -0,0 +1,44 @@ +#autoload +local tmp +local dev_tmp dpath_tmp mp_tmp mline + +case "$OSTYPE" in +linux*|irix*) + tmp=( "${(@f)$(< /etc/mtab)}" ) + dev_tmp=( "${(@)${(@)tmp%% *}:#none}" ) + mp_tmp=( "${(@)${(@)tmp#* }%% *}" ) + ;; +freebsd*|dragonfly*) + /sbin/mount | while read mline; do + dev_tmp+=( $mline[(w)1] ) + mp_tmp+=( $mline[(w)3] ) + done +;; +darwin*) + tmp=( "${(@f)$(/sbin/mount)}" ) + dev_tmp=( "${(@)${(@)tmp%% *}:#map}" ) + mp_tmp=( "${(@)${(@)tmp#* on }%% \(*}" ) + ;; +*) + /sbin/mount | while read mline; do + mp_tmp+=( $mline[(w)1] ) + dev_tmp+=( $mline[(w)3] ) + done + ;; +esac + +local MATCH MBEGIN MEND +# The complicated substitution for mount point names is required because +# characters in /etc/mtab that might confuse programs reading the names +# are encoded as exactly 3 octal digits, like for example \040 for space. +# The cleaner-looking ${(g::)mp_tmp} might consume too many digits. +# Both mp_tmp and dev_tmp are derived from /etc/mtab or "mount" output. +mp_tmp=("${(@)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}") +dev_tmp=("${(@)dev_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}") +dpath_tmp=( "${(@M)dev_tmp:#/*}" ) +dev_tmp=( "${(@)dev_tmp:#/*}" ) + +_alternative \ + 'device-labels:device label:compadd -a dev_tmp' \ + 'device-paths: device path:_canonical_paths -A dpath_tmp -N -M "r:|/=* r:|=*" device-paths device\ path' \ + 'directories:mount point:_canonical_paths -A mp_tmp -N -M "r:|/=* r:|=*" directories mount\ point' && ret=0