(mount) Handle escapes in LABEL= lines from fstab.
This commit is contained in:
parent
6d44b8033a
commit
91f7e8274e
@ -51,15 +51,25 @@ _linux_fstab()
|
||||
|
||||
# Read and unescape values into COMPREPLY
|
||||
local fs_spec fs_file fs_other
|
||||
local oldifs="$IFS"
|
||||
while read -r fs_spec fs_file fs_other; do
|
||||
__linux_fstab_unescape fs_spec
|
||||
__linux_fstab_unescape fs_file
|
||||
if [[ $fs_spec = [#]* ]]; then continue; fi
|
||||
local oldifs="$IFS"
|
||||
IFS=$'\0'
|
||||
[[ $fs_spec = */* ]] && COMPREPLY+=("$fs_spec");
|
||||
[[ $fs_file = */* ]] && COMPREPLY+=("$fs_file");
|
||||
IFS="$oldifs"
|
||||
if [[ $1 == -L ]]; then
|
||||
local fs_label=${fs_spec/#LABEL=}
|
||||
if [[ $fs_label != "$fs_spec" ]]; then
|
||||
__linux_fstab_unescape fs_label
|
||||
IFS=$'\0'
|
||||
COMPREPLY+=("$fs_label")
|
||||
IFS=$oldifs
|
||||
fi
|
||||
else
|
||||
__linux_fstab_unescape fs_spec
|
||||
__linux_fstab_unescape fs_file
|
||||
IFS=$'\0'
|
||||
[[ $fs_spec = */* ]] && COMPREPLY+=("$fs_spec")
|
||||
[[ $fs_file = */* ]] && COMPREPLY+=("$fs_file")
|
||||
IFS=$oldifs
|
||||
fi
|
||||
done
|
||||
|
||||
_reply_compgen_array
|
||||
@ -102,7 +112,7 @@ _mount()
|
||||
else
|
||||
# probably Linux
|
||||
if [ $prev = -L ]; then
|
||||
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*LABEL=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
|
||||
_linux_fstab -L < /etc/fstab
|
||||
elif [ $prev = -U ]; then
|
||||
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
|
||||
else
|
||||
|
@ -9,7 +9,7 @@ proc setup_dummy_mnt {} {
|
||||
assert_bash_exec { \
|
||||
_mnt() { \
|
||||
local cur=$(_get_cword); \
|
||||
_linux_fstab < "$TESTDIR/fixtures/mount/test-fstab"; \
|
||||
_linux_fstab $(_get_pword) < "$TESTDIR/fixtures/mount/test-fstab"; \
|
||||
}; \
|
||||
complete -F _mnt mnt \
|
||||
}
|
||||
@ -99,6 +99,12 @@ sync_after_int
|
||||
assert_complete {/mnt/other\'test\ path} {mnt /mnt/other}
|
||||
sync_after_int
|
||||
|
||||
assert_complete {Ubuntu\ Karmic} {mnt -L Ubu}
|
||||
sync_after_int
|
||||
|
||||
assert_complete {Debian-it\'s\ awesome} {mnt -L Deb}
|
||||
sync_after_int
|
||||
|
||||
# This does not work. Proper support for this requires smarter parsing of
|
||||
# $COMP_LINE and it's not worth doing just for mount.
|
||||
#assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n}
|
||||
|
Loading…
x
Reference in New Issue
Block a user