Merge branch 'master' of git+ssh://git.debian.org/git/bash-completion/bash-completion
This commit is contained in:
commit
1ab50e301e
2
CHANGES
2
CHANGES
@ -88,6 +88,8 @@ bash-completion (1.x)
|
||||
* Improve rpm group completion (displayed completions are still wrong).
|
||||
* Change many completions to load in memory only if the completed commands
|
||||
are available.
|
||||
* Invoke the actual mplayer/mencoder command being completed (with full path)
|
||||
to get various completions instead of simply "mplayer" or "mencoder".
|
||||
|
||||
[ Todd Zullinger ]
|
||||
* Make yum complete on filenames after install, deplist, update and upgrade
|
||||
|
@ -1084,6 +1084,8 @@ _known_hosts_real()
|
||||
p) prefix=$OPTARG ;;
|
||||
esac
|
||||
done
|
||||
[ $# -ge $OPTIND ] && echo "error: $FUNCNAME("$@"): unprocessed arguments:"\
|
||||
$(while [ $# -gt 0 ]; do echo ${!OPTIND}; shift; done)
|
||||
|
||||
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
|
||||
kh=()
|
||||
|
@ -22,12 +22,8 @@ _mplayer()
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
case "$prev" in
|
||||
-@(ac|afm|vc|vfm|ao|vo|vop|fstype|demuxer|vf|af))
|
||||
_mplayer_options_list mplayer $prev
|
||||
return 0
|
||||
;;
|
||||
-@(oac|ovc|of))
|
||||
_mplayer_options_list mencoder $prev
|
||||
-@([av][cfo]|[av]fm|vop|fstype|demuxer|o[av]c|of|profile))
|
||||
_mplayer_options_list $cmd $prev
|
||||
return 0
|
||||
;;
|
||||
-audiofile)
|
||||
@ -250,10 +246,6 @@ _mplayer()
|
||||
COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) )
|
||||
return 0
|
||||
;;
|
||||
-profile)
|
||||
_mplayer_options_list $cmd $prev
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
|
@ -94,7 +94,7 @@ _ssh()
|
||||
fi
|
||||
shift
|
||||
done
|
||||
_known_hosts_real -a "$optconfigfile" -h "$cur"
|
||||
_known_hosts_real -a -h "$cur" $optconfigfile
|
||||
if [ $COMP_CWORD -ne 1 ]; then
|
||||
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
|
||||
fi
|
||||
@ -144,7 +144,7 @@ _sftp()
|
||||
fi
|
||||
shift
|
||||
done
|
||||
_known_hosts_real -a "$optconfigfile" -h "$cur"
|
||||
_known_hosts_real -a -h "$cur" $optconfigfile
|
||||
fi
|
||||
|
||||
return 0
|
||||
@ -200,7 +200,7 @@ _scp()
|
||||
shift
|
||||
done
|
||||
|
||||
[[ "$cur" == */* ]] || _known_hosts_real -c -a "$optconfigfile" -h "$cur"
|
||||
[[ "$cur" == */* ]] || _known_hosts_real -c -a -h "$cur" $optconfigfile
|
||||
|
||||
# This approach is used instead of _filedir to get a space appended
|
||||
# after local file/dir completions, and $nospace retained for others.
|
||||
|
@ -24,18 +24,7 @@ sync_after_int
|
||||
|
||||
|
||||
set test "Tab should complete partial username"
|
||||
# Build string list of usernames, starting with the character of the
|
||||
# first username.
|
||||
set users {}
|
||||
set char ""
|
||||
foreach u [exec bash -c "compgen -A user"] {
|
||||
if {$char == ""} {set char [string range $u 0 0]}
|
||||
# Only append username if starting with $char
|
||||
if {[string range $u 0 0] == "$char"} {
|
||||
lappend users $u
|
||||
}; # if
|
||||
}; # foreach
|
||||
assert_complete $users "finger $char" $test
|
||||
assert_complete_partial [exec bash -c "compgen -A user"] "finger"
|
||||
|
||||
|
||||
sync_after_int
|
||||
|
@ -42,4 +42,31 @@ expect {
|
||||
sync_after_int
|
||||
|
||||
|
||||
set test "First argument shouldn't complete with commands"
|
||||
# NOTE: This test assumes the machine running this test has a command "bash"
|
||||
# but no host named "bash" ...
|
||||
set cmd "ssh bas"
|
||||
send "$cmd\t"
|
||||
expect -ex "$cmd"
|
||||
expect {
|
||||
-timeout 1
|
||||
# In case multiple commands `bas*' are completed
|
||||
-re "^\r\n.*bash.*\r\n/@$cmd$" { fail "$test" }
|
||||
# In case the single command `bash' is completed
|
||||
-re "h $" { fail "$test" }
|
||||
-re ".+" { unresolved "$test" }
|
||||
timeout { pass "$test" }
|
||||
}; # expect
|
||||
|
||||
|
||||
sync_after_int
|
||||
|
||||
|
||||
set test "Tab should complete partial hostname"
|
||||
assert_complete_partial [get_hosts] "ssh"
|
||||
|
||||
|
||||
sync_after_int
|
||||
|
||||
|
||||
teardown
|
||||
|
@ -56,9 +56,9 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
|
||||
send "$cmd\t"
|
||||
if {[llength $expected] == 1} {
|
||||
expect -ex "$cmd"
|
||||
# Assume second word is word to complete on.
|
||||
# Assume second word is word to complete on.
|
||||
set cur [lindex [split $cmd] 1]
|
||||
# Remove second word from beginning of single item $expected
|
||||
# Remove second word from beginning of single item $expected
|
||||
if {[string first $cur $expected] == 0} {
|
||||
set expected [string range $expected [string length $cur] end]
|
||||
}; # if
|
||||
@ -82,6 +82,33 @@ proc assert_complete {expected cmd {test ""} {prompt /@} {size 20}} {
|
||||
}; # assert_complete()
|
||||
|
||||
|
||||
# Make sure a partial argument is completed.
|
||||
# A completion is tried with `$partial', or if this is empty, the first
|
||||
# character of the first item of `$expected'. Only the items from $expected,
|
||||
# starting with this character are then expected as completions.
|
||||
# @param list $expected List of all completions.
|
||||
# @param string $cmd Command given to generate items
|
||||
# @param string $test (optional) Test titel. Default is "$cmd<TAB> should show completions"
|
||||
# @param integer $size (optional) Chunk size. Default is 20.
|
||||
# @result boolean True if successful, False if not
|
||||
proc assert_complete_partial {expected cmd {partial ""} {test ""} {prompt /@} {size 20}} {
|
||||
if {$test == ""} {set test "$cmd should complete partial argument"}
|
||||
if {[llength $expected] == 0} {
|
||||
unresolved "$test"
|
||||
} else {
|
||||
set pick {}
|
||||
foreach item $expected {
|
||||
if {$partial == ""} {set partial [string range $item 0 0]}
|
||||
# Only append item if starting with $partial
|
||||
if {[string range $item 0 [expr [string length $partial] - 1]] == "$partial"} {
|
||||
lappend pick $item
|
||||
}; # if
|
||||
}; # foreach
|
||||
assert_complete $pick "$cmd $partial" $test $prompt $size
|
||||
}; # if
|
||||
}; # assert_complete_partial()
|
||||
|
||||
|
||||
# Make sure any completions are returned
|
||||
proc assert_complete_any {cmd {test ""} {prompt /@}} {
|
||||
if {$test == ""} {set test "$cmd should show completions"}
|
||||
@ -186,6 +213,18 @@ proc assert_exec {cmd {stdout ''} {test ''}} {
|
||||
}; # assert_exec()
|
||||
|
||||
|
||||
# Get known hostnames
|
||||
# @return list Hostnames
|
||||
proc get_hosts {} {
|
||||
set hosts [exec bash -c "compgen -A hostname"]
|
||||
lappend hosts [exec bash -c {
|
||||
type avahi-browse >&/dev/null &&
|
||||
avahi-browse -kcpr _workstation._tcp | grep ^= | cut -d\; -f7 | sort -u
|
||||
}]
|
||||
return $hosts
|
||||
}; # get_hosts()
|
||||
|
||||
|
||||
# Expect items.
|
||||
# Break items into chunks because `expect' seems to have a limited buffer size
|
||||
# @param list $items
|
||||
@ -201,13 +240,24 @@ proc match_items {items test {size 20}} {
|
||||
# Escape special regexp characters
|
||||
regsub -all {([\[\]\(\)\.\\\+])} $item {\\\1} item
|
||||
append expected $item
|
||||
if {[llength $items] > 1} {append expected {\s+}}
|
||||
if {[llength $items] > 1} {append expected {\s+}};
|
||||
}; # for
|
||||
expect {
|
||||
-re "$expected" { set result true }
|
||||
default { set result false; break }
|
||||
timeout { set result false; break }
|
||||
}; # expect
|
||||
if {[llength $items] == 1} {
|
||||
expect {
|
||||
-timeout 1
|
||||
-re "$expected" { set result true }
|
||||
"\r\n" { set result false; break }
|
||||
default { set result false; break }
|
||||
timeout { set result false; break }
|
||||
}; # expect
|
||||
} else {
|
||||
expect {
|
||||
-timeout 1
|
||||
-re "$expected" { set result true }
|
||||
default { set result false; break }
|
||||
timeout { set result false; break }
|
||||
}; # expect
|
||||
}; # if
|
||||
}; # for
|
||||
return $result
|
||||
}; # match_items()
|
||||
|
@ -12,11 +12,7 @@ setup
|
||||
|
||||
|
||||
set test "Hosts should be put in COMPREPLY"
|
||||
|
||||
# Build string list of hostnames, separated by regexp whitespace marker (\s+).
|
||||
# Example string: host1\s+host2\s+host3
|
||||
|
||||
set hosts [exec bash -c "compgen -A hostname"]
|
||||
set hosts [get_hosts]
|
||||
# Hosts `gee' and `hus' are defined in ./fixtures/_known_hosts_real/config
|
||||
# Hosts `doo' and `ike' are defined in ./fixtures/_known_hosts_real/known_hosts
|
||||
lappend hosts doo gee hus ike
|
||||
@ -37,9 +33,7 @@ sync_after_int
|
||||
|
||||
|
||||
set test "Config file containing space should work"
|
||||
# Build string list of hostnames, separated by regexp whitespace marker (\s+).
|
||||
# Example string: host1\s+host2\s+host3
|
||||
set hosts [exec bash -c "compgen -A hostname"]
|
||||
set hosts [get_hosts]
|
||||
# Hosts `gee' and `hus' are defined in ./fixtures/_known_hosts_real/spaced conf
|
||||
# Hosts `doo' and `ike' are defined in ./fixtures/_known_hosts_real/known_hosts
|
||||
# Host `two' is defined in ./fixtures/_known_hosts_real/known_hosts2
|
||||
@ -47,7 +41,7 @@ lappend hosts gee hus doo ike two
|
||||
set hosts [lsort -ascii $hosts]
|
||||
set hosts [join $hosts "\\s+"]
|
||||
# Call _known_hosts
|
||||
set cmd {_known_hosts -aF 'fixtures/_known_hosts_real/spaced conf'; echo_array COMPREPLY}
|
||||
set cmd {_known_hosts_real -aF 'fixtures/_known_hosts_real/spaced conf'; echo_array COMPREPLY}
|
||||
send "$cmd\r"
|
||||
expect -ex "$cmd\r\n"
|
||||
expect {
|
||||
|
Loading…
x
Reference in New Issue
Block a user