diff options
-rw-r--r-- | contrib/mount | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/contrib/mount b/contrib/mount index c15f798f..b581bc27 100644 --- a/contrib/mount +++ b/contrib/mount @@ -8,6 +8,7 @@ have mount && { # Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better! +# # This will correctly escape special characters in COMPREPLY. _reply_compgen_array() { @@ -33,11 +34,29 @@ _reply_compgen_array() # Strip starting $' in reply if present in cur. # This is necesarry because readline interprets everything after ' as a # separate word for completion. - if [[ $cur == $\'* ]]; then + if [[ $cur == $\'* ]]; then #' COMPREPLY=( "${COMPREPLY[@]/#$\'}" ) fi } +# Complete linux fstab entries. +# +# Reads a file from stdin in the linux fstab(5) format; as used by /etc/fstab +# and /proc/mounts. +_linux_fstab() +{ + COMPREPLY=() + + # Read and unescape values into COMPREPLY + while read -r fs_spec fs_file fs_other; do + if [[ $fs_spec = [#]* ]]; then continue; fi + [[ $fs_spec = */* ]] && { IFS=$'\0' eval "COMPREPLY+=( $'$fs_spec' )"; } + [[ $fs_file = */* ]] && { IFS=$'\0' eval "COMPREPLY+=( $'$fs_file' )"; } + done + + _reply_compgen_array +} + _mount() { local cur sm host prev @@ -79,14 +98,7 @@ _mount() elif [ $prev = -U ]; then COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) ) else - COMPREPLY=() - while read -r fs_spec fs_file fs_other; do - if [[ $fs_spec = [#]* ]]; then continue; fi - [[ $fs_spec = */* ]] && { IFS=$'\0' eval "COMPRELPY+=( $'$fs_spec' )"; } - [[ $fs_file = */* ]] && { IFS=$'\0' eval "COMPREPLY+=( $'$fs_file' )"; } - done < /etc/fstab - - _reply_compgen_array + _linux_fstab < /etc/fstab fi fi |