diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2017-08-02 15:10:02 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2017-08-08 14:55:02 +0000 |
commit | 5654b905f96720bef285dc92d6b2e2cc31bd971e (patch) | |
tree | 0e9640e4c0088ffaff653fee2aa0318c52b7d500 /Completion/Unix/Type | |
parent | e2124c47193f57bdc5a19061e2e9bc6969fda32e (diff) | |
download | zsh-5654b905f96720bef285dc92d6b2e2cc31bd971e.tar.gz zsh-5654b905f96720bef285dc92d6b2e2cc31bd971e.tar.xz zsh-5654b905f96720bef285dc92d6b2e2cc31bd971e.zip |
41481: _df: Complete mounted device and mount points.
This splits umount's "udevordir" completion from _mount to a new file, without changing it.
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r-- | Completion/Unix/Type/_umountable | 44 |
1 files changed, 44 insertions, 0 deletions
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 |