Fix NFS mounts completion (Alioth: #312285).

master
Leonard Crestez 2010-01-24 19:25:16 +02:00 committed by Ville Skyttä
parent 258736a47b
commit c5951118e9
5 changed files with 52 additions and 3 deletions

View File

@ -66,6 +66,7 @@ bash-completion (2.x)
[ Leonard Crestez ]
* Improve ssh -o suboption completion (Alioth: #312122).
* Fix NFS mounts completion (Alioth: #312285).
[ Raphaël Droz ]
* Add xsltproc completion (Alioth: #311843).

View File

@ -12,9 +12,9 @@ _mount()
local cur i sm host prev
COMPREPLY=()
cur=`_get_cword`
cur=`_get_cword ':'`
prev=`_get_pword ':'`
[[ "$cur" == \\ ]] && cur="/"
prev=${COMP_WORDS[COMP_CWORD-1]}
for i in $(type -P showmount) {,/usr}/{,s}bin/showmount; do
[ -x $i ] && sm=$i && break
@ -22,7 +22,7 @@ _mount()
if [[ -n "$sm" && "$cur" == *:* ]]; then
COMPREPLY=( $( compgen -W "$( $sm -e ${cur%%:*} | \
awk 'NR>1 {print $1}' )" -- "$cur" ) )
awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) )
elif [[ "$cur" == //* ]]; then
host=${cur#//}
host=${host%%/*}

View File

@ -0,0 +1,3 @@
if {[assert_bash_type mount]} {
source "lib/completions/mount.exp"
}; # if

12
test/fixtures/mount/bin/showmount vendored Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
if [ "$1" = -e ] && [ "$2" = mocksrv ]; then
echo "Header line"
echo "/test/path"
echo "/test/path2"
echo "/second/path"
exit 0
fi
echo "Usage: 'showmount -e mocksrv'; nothing else works."
exit 1

View File

@ -0,0 +1,33 @@
proc setup {} {
save_env
};
proc teardown {} {
assert_env_unmodified
};
setup
assert_complete_any "mount "
sync_after_int
set test "Check completing nfs mounts"
set expected [list /test/path /test/path2 /second/path]
set cmd "mount mocksrv:/"
assert_bash_exec {OLDPATH="$PATH"; PATH="$TESTDIR/fixtures/mount/bin:$PATH";}
# This needs an explicit cword param or will output "unresolved".
assert_complete $expected $cmd $test "/@" 20 "/"
sync_after_int
assert_bash_exec {PATH="$OLDPATH"; unset -v OLDPATH}
sync_after_int
teardown