Use _init_completion() in bash_completion.

This commit is contained in:
Ville Skyttä 2011-04-20 13:14:04 +03:00
parent 32dbe76784
commit 955219bf69

View File

@ -1275,11 +1275,10 @@ _dvd_devices()
# This function provides simple user@host completion # This function provides simple user@host completion
# #
_user_at_host() { _user_at_host()
local cur {
local cur prev words cword
COMPREPLY=() _init_completion -n : || return
_get_comp_words_by_ref -n : cur
if [[ $cur == *@* ]]; then if [[ $cur == *@* ]]; then
_known_hosts_real "$cur" _known_hosts_real "$cur"
@ -1295,14 +1294,15 @@ shopt -u hostcomplete && complete -F _user_at_host -o nospace talk ytalk finger
# `_known_hosts_real' instead. # `_known_hosts_real' instead.
_known_hosts() _known_hosts()
{ {
local options local cur prev words cword
COMPREPLY=() _init_completion -n : || return
# NOTE: Using `_known_hosts' as a helper function and passing options # NOTE: Using `_known_hosts' as a helper function and passing options
# to `_known_hosts' is deprecated: Use `_known_hosts_real' instead. # to `_known_hosts' is deprecated: Use `_known_hosts_real' instead.
local options
[[ "$1" == -a || "$2" == -a ]] && options=-a [[ "$1" == -a || "$2" == -a ]] && options=-a
[[ "$1" == -c || "$2" == -c ]] && options+=" -c" [[ "$1" == -c || "$2" == -c ]] && options+=" -c"
_known_hosts_real $options "$(_get_cword :)" _known_hosts_real $options "$cur"
} # _known_hosts() } # _known_hosts()
# Helper function for completing _known_hosts. # Helper function for completing _known_hosts.
@ -1472,9 +1472,10 @@ complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 ping \
# #
_cd() _cd()
{ {
local cur IFS=$'\n' i j k local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
local IFS=$'\n' i j k
# try to allow variable completion # try to allow variable completion
if [[ "$cur" == ?(\\)\$* ]]; then if [[ "$cur" == ?(\\)\$* ]]; then
COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) ) COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
@ -1643,9 +1644,10 @@ _complete_as_root()
_longopt() _longopt()
{ {
local cur prev split=false local cur prev words cword
_get_comp_words_by_ref -n = cur prev _init_completion -n = || return
local split=false
_split_longopt && split=true _split_longopt && split=true
case "$prev" in case "$prev" in
@ -1684,14 +1686,12 @@ unset i
_filedir_xspec() _filedir_xspec()
{ {
local IFS cur xspec local cur prev words cword
_init_completion || return
IFS=$'\n'
COMPREPLY=()
_get_comp_words_by_ref cur
_expand || return 0 _expand || return 0
local IFS=$'\n' xspec
# get first exclusion compspec that matches this command # get first exclusion compspec that matches this command
xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \ xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \
"$BASH_COMPLETION" ) "$BASH_COMPLETION" )