diff options
author | Crestez Dan Leonard <cdleonard@gmail.com> | 2010-02-15 15:33:10 +0200 |
---|---|---|
committer | Crestez Dan Leonard <cdleonard@gmail.com> | 2010-02-15 15:33:10 +0200 |
commit | 91f7e8274e90632c95527bf0fc1407e9abd0b539 (patch) | |
tree | fdc3aed0137d0b38a902a153e90b63b20e73d205 | |
parent | 6d44b8033a2993e965c8b1fa97cba9d11fa7022e (diff) | |
download | bash-completion-91f7e8274e90632c95527bf0fc1407e9abd0b539.tar.gz |
(mount) Handle escapes in LABEL= lines from fstab.
-rw-r--r-- | contrib/mount | 26 | ||||
-rw-r--r-- | test/lib/completions/mount.exp | 8 |
2 files changed, 25 insertions, 9 deletions
diff --git a/contrib/mount b/contrib/mount index 6fbb24fa..26b78ead 100644 --- a/contrib/mount +++ b/contrib/mount @@ -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 diff --git a/test/lib/completions/mount.exp b/test/lib/completions/mount.exp index 4473c70f..9e98cc6d 100644 --- a/test/lib/completions/mount.exp +++ b/test/lib/completions/mount.exp @@ -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} |