summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrestez Dan Leonard <cdleonard@gmail.com>2010-02-04 16:47:44 +0200
committerCrestez Dan Leonard <cdleonard@gmail.com>2010-02-04 16:47:44 +0200
commit1096dadc26c9c4c9297a2b784e96b57e4c3bf208 (patch)
tree370e5b7067305784c0b2589e0510f8f2400d4637
parent800453c30ed0cc109b6fe4baad6094868b6646b4 (diff)
downloadbash-completion-1096dadc26c9c4c9297a2b784e96b57e4c3bf208.tar.gz
Separate _linux_fstab function
-rw-r--r--contrib/mount30
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