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