[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-101-g59e189e

Ville Skyttä ville.skytta at iki.fi
Thu Apr 21 08:16:27 UTC 2011


The following commit has been merged in the master branch:
commit 8048917968a679f3eecfd5fd237a7ee2823ab855
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Thu Apr 21 11:04:51 2011 +0300

    Use _init_completion() in completions/[q-z]*.

diff --git a/completions/qdbus b/completions/qdbus
index 2b7f2e7..ffdea33 100644
--- a/completions/qdbus
+++ b/completions/qdbus
@@ -4,13 +4,11 @@ have qdbus || have dcop || return
 
 _qdbus()
 {
-    local cur
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
-
-    [ -n "$cur" ] && unset COMP_WORDS[${#COMP_WORDS[@]}-1]
-    COMPREPLY=( $( compgen -W '$( command ${COMP_WORDS[@]} 2>/dev/null | \
+    [ -n "$cur" ] && unset words[${#words[@]}-1]
+    COMPREPLY=( $( compgen -W '$( command ${words[@]} 2>/dev/null | \
         sed s/\(.*\)// )' -- "$cur" ) )
 } &&
 complete -F _qdbus qdbus dcop
diff --git a/completions/qemu b/completions/qemu
index 5cac45e..f093399 100644
--- a/completions/qemu
+++ b/completions/qemu
@@ -4,10 +4,8 @@ have qemu || return
 
 _qemu()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -fd[ab]|-hd[abcd]|-cdrom|-option-rom|-kernel|-initrd|-bootp|-pidfile| \
diff --git a/completions/quota-tools b/completions/quota-tools
index e293141..bc06607 100644
--- a/completions/quota-tools
+++ b/completions/quota-tools
@@ -7,8 +7,8 @@ _user_or_group()
     local i
 
     # complete on groups if -g was given
-    for (( i=1; i < COMP_CWORD; i++ )); do
-        if [[ "${COMP_WORDS[i]}" == -g ]]; then
+    for (( i=1; i < cword; i++ )); do
+        if [[ "${words[i]}" == -g ]]; then
             COMPREPLY=( $( compgen -g -- "$cur" ) )
             return 0
         fi
@@ -33,11 +33,10 @@ _filesystems()
 
 _quota()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -62,11 +61,10 @@ complete -F _quota -o default quota
 
 _setquota()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -101,11 +99,10 @@ complete -F _setquota -o default setquota
 
 _edquota()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -133,11 +130,10 @@ complete -F _edquota -o default edquota
 
 _quotacheck()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -162,11 +158,10 @@ complete -F _quotacheck -o default quotacheck
 
 _repquota()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -191,11 +186,10 @@ complete -F _repquota -o default repquota
 
 _quotaon()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -218,11 +212,10 @@ complete -F _quotaon -o default quotaon
 
 _quotaoff()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/rcs b/completions/rcs
index 30b08f9..9b15010 100644
--- a/completions/rcs
+++ b/completions/rcs
@@ -4,10 +4,10 @@ have rcs || return
 
 _rcs()
 {
-    local cur prev file dir i
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local file dir i
 
     file=${cur##*/}
     dir=${cur%/*}
diff --git a/completions/rdesktop b/completions/rdesktop
index 267f75f..cb83a5d 100644
--- a/completions/rdesktop
+++ b/completions/rdesktop
@@ -4,10 +4,8 @@ have rdesktop || return
 
 _rdesktop()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -k)
diff --git a/completions/reportbug b/completions/reportbug
index 0c44bd6..223bcf3 100644
--- a/completions/reportbug
+++ b/completions/reportbug
@@ -3,10 +3,8 @@
 have reportbug &&
 _reportbug()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -f|--filename|-i|--include|--mta|-o|--output)
@@ -19,8 +17,8 @@ _reportbug()
             return 0
             ;;
         -e|--editor|--mua)
-            COMP_WORDS=(COMP_WORDS[0] "$cur")
-            COMP_CWORD=1
+            words=(words[0] "$cur")
+            cword=1
             _command
             return 0
             ;;
@@ -89,11 +87,10 @@ complete -F _reportbug reportbug
 have querybts &&
 _querybts()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/reptyr b/completions/reptyr
index d1ccdb3..4d1a9c4 100644
--- a/completions/reptyr
+++ b/completions/reptyr
@@ -4,10 +4,8 @@ have reptyr || return
 
 _reptyr()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -l)
diff --git a/completions/resolvconf b/completions/resolvconf
index f21adc3..83cbdb0 100644
--- a/completions/resolvconf
+++ b/completions/resolvconf
@@ -4,10 +4,8 @@ have resolvconf || return
 
 _resolvconf()
 {
-    local cur command
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -a|-d)
diff --git a/completions/rfkill b/completions/rfkill
index 50e79ab..f0d4f1c 100644
--- a/completions/rfkill
+++ b/completions/rfkill
@@ -4,15 +4,13 @@ have rfkill || return
 
 _rfkill()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '--version' -- "$cur" ) )
     else
-        case $COMP_CWORD in
+        case $cword in
             1)
                 COMPREPLY=( $( compgen -W "help event list block unblock" \
                     -- "$cur" ) )
diff --git a/completions/ri b/completions/ri
index f2c152a..f0658d7 100644
--- a/completions/ri
+++ b/completions/ri
@@ -35,11 +35,11 @@ ri_get_methods()
 # needs at least Ruby 1.8.0 in order to use -W0
 _ri()
 {
-    local cur class method prefix ri_path ri_version separator IFS
-    local -a classes
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local class method prefix ri_path ri_version separator IFS
+    local -a classes
 
     ri_path=$(type -p ri)
     # which version of ri are we using?
diff --git a/completions/rpcdebug b/completions/rpcdebug
index f1590a6..facc851 100644
--- a/completions/rpcdebug
+++ b/completions/rpcdebug
@@ -7,9 +7,9 @@ _rpcdebug_flags()
 
     local i module
 
-    for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
-        if [[ ${COMP_WORDS[i]} == -m ]]; then
-            module=${COMP_WORDS[i+1]}
+    for (( i=0; i < ${#words[@]}; i++ )); do
+        if [[ ${words[i]} == -m ]]; then
+            module=${words[i+1]}
         fi
     done
 
@@ -21,10 +21,8 @@ _rpcdebug_flags()
 
 _rpcdebug()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -s)
diff --git a/completions/rpm b/completions/rpm
index 94ce656..005cfbd 100644
--- a/completions/rpm
+++ b/completions/rpm
@@ -39,12 +39,10 @@ _rpm_macros()
 #
 _rpm()
 {
-    local cur prev opts
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
-
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         # first parameter on line
         case $cur in
             --*)
@@ -117,10 +115,10 @@ _rpm()
     esac
 
     # options common to all modes
-    opts="--define --eval --macros --nodigest --nosignature --rcfile \
+    local opts="--define --eval --macros --nodigest --nosignature --rcfile \
         --quiet --pipe --verbose"
 
-    case ${COMP_WORDS[1]} in
+    case ${words[1]} in
         -[iFU]*|--install|--freshen|--upgrade)
             if [[ "$cur" == -* ]]; then
                 COMPREPLY=( $( compgen -W "$opts --percent --force \
@@ -152,7 +150,7 @@ _rpm()
                 --list --obsoletes --pipe --provides --queryformat --rcfile
                 --requires --scripts --suggests --triggers --xml"
 
-            if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
+            if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
                 # -qf completion
                 if [[ "$cur" == -* ]]; then
                     COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \
@@ -160,10 +158,10 @@ _rpm()
                 else
                     _filedir
                 fi
-            elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
+            elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
                 # -qg completion
                 _rpm_groups $1
-            elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
+            elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
                 # -qp; uninstalled package completion
                 if [[ "$cur" == -* ]]; then
                     COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \
@@ -179,7 +177,7 @@ _rpm()
                         --package --pkgid --root --specfile --state 
                         --triggeredby --whatprovides --whatrequires" \
                             -- "$cur" ) )
-                elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then
+                elif [[ ${words[@]} != *\ -@(*([^ -])a|-all )* ]]; then
                     _rpm_installed_packages $1
                 fi
             fi
@@ -199,11 +197,11 @@ _rpm()
                     --nofiles --noscripts --nomd5 --querytags --specfile \
                     --whatrequires --whatprovides" -- "$cur" ) )
             # check whether we're doing file completion
-            elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
+            elif [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
                 _filedir
-            elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
+            elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
                 _rpm_groups $1
-            elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
+            elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
                 _filedir '[rs]pm'
             else
                 _rpm_installed_packages $1
@@ -231,10 +229,10 @@ complete -F _rpm rpm
 
 _rpmbuild()
 {
-    COMPREPLY=()
-    local cur prev words split=false
-    _get_comp_words_by_ref cur prev words
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     local rpm="${1%build*}"
@@ -304,14 +302,10 @@ complete -F _rpmbuild rpmbuild rpmbuild-md5
 have gendiff &&
 _gendiff()
 {
-    COMPREPLY=()
-    local cur prev cword
-    _get_comp_words_by_ref cur prev cword
-    if [[ $cword -eq 1 ]]; then
-        _filedir -d
-    elif [[ $prev == *\> ]]; then
-        _filedir
-    fi
+    local cur prev words cword
+    _init_completion -o @(diff|patch) || return
+
+    [[ $cword -eq 1 ]] && _filedir -d
 } &&
 complete -F _gendiff gendiff
 
diff --git a/completions/rpmcheck b/completions/rpmcheck
index 9dd3311..16d96da 100644
--- a/completions/rpmcheck
+++ b/completions/rpmcheck
@@ -4,10 +4,8 @@ have rpmcheck || return
 
 _rpmcheck()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -base)
diff --git a/completions/rrdtool b/completions/rrdtool
index b2ad71f..817b1ae 100644
--- a/completions/rrdtool
+++ b/completions/rrdtool
@@ -4,8 +4,8 @@ have rrdtool || return
 
 _rrdtool ()
 {
-    local cur
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     COMPREPLY=( $( compgen -W 'create update updatev graph dump restore last \
         lastupdate first info fetch tune resize xport' -- "$cur" ) )
diff --git a/completions/rsync b/completions/rsync
index 1299202..5c07db4 100644
--- a/completions/rsync
+++ b/completions/rsync
@@ -4,11 +4,10 @@ have rsync || return
 
 _rsync()
 {
-    # TODO: _split_longopt
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref -n : cur prev
+    # TODO: _split_longopt
 
     _expand || return 0
 
@@ -65,9 +64,9 @@ _rsync()
             if type _scp_remote_files &>/dev/null; then
                 # find which remote shell is used
                 local i shell=ssh
-                for (( i=1; i < COMP_CWORD; i++ )); do
-                    if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then
-                        shell=${COMP_WORDS[i+1]}
+                for (( i=1; i < cword; i++ )); do
+                    if [[ "${words[i]}" == -@(e|-rsh) ]]; then
+                        shell=${words[i+1]}
                         break
                     fi
                 done
diff --git a/completions/rtcwake b/completions/rtcwake
index 9f2e896..7cfb49b 100644
--- a/completions/rtcwake
+++ b/completions/rtcwake
@@ -4,10 +4,10 @@ have rtcwake || return
 
 _rtcwake()
 {
-    COMPREPLY=()
-    local cur prev split=false
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case "$prev" in
diff --git a/completions/samba b/completions/samba
index 7568a56..a08b9ee 100644
--- a/completions/samba
+++ b/completions/samba
@@ -30,11 +30,10 @@ _samba_debuglevel()
 
 _smbclient()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -96,11 +95,10 @@ complete -F _smbclient smbclient
 
 _smbget()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -128,11 +126,10 @@ complete -F _smbget smbget
 
 _smbcacls()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -161,11 +158,10 @@ complete -F _smbcacls smbcacls
 
 _smbcquotas()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -195,10 +191,8 @@ complete -F _smbcquotas smbcquotas
 
 _smbpasswd()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -r)
@@ -228,10 +222,8 @@ complete -F _smbpasswd smbpasswd
 
 _smbtar()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -r|-t)
@@ -257,11 +249,10 @@ complete -F _smbtar smbtar
 
 _smbtree()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/sbcl b/completions/sbcl
index 7bf1ab9..85d0b43 100644
--- a/completions/sbcl
+++ b/completions/sbcl
@@ -5,10 +5,8 @@ have sbcl || have sbcl-mt || return
 
 _sbcl()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     # completing an option (may or may not be separated by a space)
     if [[ "$cur" == -* ]]; then
diff --git a/completions/screen b/completions/screen
index 15aaa78..e2d99bd 100644
--- a/completions/screen
+++ b/completions/screen
@@ -11,9 +11,7 @@ _screen_sessions()
 _screen()
 {
     local cur prev words cword
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev words cword
+    _init_completion || return
 
     if ((cword > 2)); then
         case ${words[cword-2]} in
diff --git a/completions/service b/completions/service
index f45c530..515c6d1 100644
--- a/completions/service
+++ b/completions/service
@@ -8,17 +8,16 @@
 
 _service()
 {
-    local cur prev sysvdir
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     # don't complete past 2nd token
-    [ $COMP_CWORD -gt 2 ] && return 0
+    [ $cword -gt 2 ] && return 0
 
-    if [[ $COMP_CWORD -eq 1 && $prev == "service" ]]; then
+    if [[ $cword -eq 1 && $prev == service ]]; then
         _services
     else
+        local sysvdir
         [ -d /etc/rc.d/init.d ] && \
             sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
         COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
diff --git a/completions/sh b/completions/sh
index 79a546a..2ca56e8 100644
--- a/completions/sh
+++ b/completions/sh
@@ -4,9 +4,8 @@ have sh || return
 
 _sh()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -c)
diff --git a/completions/shadow b/completions/shadow
index 058c139..82bdf52 100644
--- a/completions/shadow
+++ b/completions/shadow
@@ -3,11 +3,10 @@
 have useradd &&
 _useradd()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     # TODO: if -o/--non-unique is given, could complete on existing uids
@@ -54,11 +53,10 @@ complete -F _useradd useradd
 have usermod &&
 _usermod()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     # TODO: if -o/--non-unique is given, could complete on existing uids
@@ -103,10 +101,8 @@ complete -F _usermod usermod
 have userdel &&
 _userdel()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '--force --help --remove' -- "$cur" ) )
@@ -120,11 +116,10 @@ complete -F _userdel userdel
 have chage &&
 _chage()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -149,10 +144,8 @@ complete -F _chage chage
 have passwd &&
 _passwd()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -n|-x|-w|-i|-\?|--help|--usage)
@@ -173,11 +166,10 @@ complete -F _passwd passwd
 have chpasswd &&
 _chpasswd()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -204,11 +196,10 @@ complete -F _chpasswd chpasswd
 have newusers &&
 _newusers()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -237,10 +228,8 @@ complete -F _newusers newusers
 have pwck &&
 _pwck()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) )
@@ -254,11 +243,10 @@ complete -F _pwck pwck
 have groupadd &&
 _groupadd()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     # TODO: if -o/--non-unique is given, could complete on existing gids
@@ -283,11 +271,10 @@ complete -F _groupadd groupadd
 have groupmod &&
 _groupmod()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     # TODO: if -o/--non-unique is given, could complete on existing gids
@@ -316,9 +303,8 @@ complete -g groupdel
 have newgrp &&
 _newgrp()
 {
-    local cur
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == "-" ]]; then
         COMPREPLY=( - )
@@ -331,10 +317,8 @@ complete -F _newgrp newgrp
 have gpasswd &&
 _gpasswd()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -a|-d|-A|-M)
@@ -355,10 +339,8 @@ complete -F _gpasswd gpasswd
 have groupmems &&
 _groupmems()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -a|-d)
@@ -381,10 +363,8 @@ complete -F _groupmems groupmems
 have grpck &&
 _grpck()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) )
@@ -398,10 +378,8 @@ complete -F _grpck grpck
 have vipw || have vigr &&
 _vipw()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -h|--help)
@@ -420,11 +398,10 @@ complete -F _vipw vipw vigr
 have faillog &&
 _faillog()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
@@ -450,11 +427,10 @@ complete -F _faillog faillog
 have lastlog &&
 _lastlog()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/sitecopy b/completions/sitecopy
index 2535e85..d0dc902 100644
--- a/completions/sitecopy
+++ b/completions/sitecopy
@@ -6,10 +6,8 @@ have sitecopy || return
 
 _sitecopy()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     case $cur in
         --*)
diff --git a/completions/smartctl b/completions/smartctl
index 1930848..e7e7183 100644
--- a/completions/smartctl
+++ b/completions/smartctl
@@ -105,11 +105,10 @@ _smartctl_drivedb()
 
 _smartctl()
 {
-    local cur prev split=false
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/snownews b/completions/snownews
index c579bca..ee7ec98 100644
--- a/completions/snownews
+++ b/completions/snownews
@@ -4,10 +4,8 @@ have snownews || return
 
 _snownews()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         # return list of available options
diff --git a/completions/sqlite3 b/completions/sqlite3
index 75618d2..fe76652 100644
--- a/completions/sqlite3
+++ b/completions/sqlite3
@@ -4,9 +4,8 @@ have sqlite3 || return
 
 _sqlite3()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     local dbexts='@(sqlite?(3)|?(s?(3))db)'
 
diff --git a/completions/ssh b/completions/ssh
index 3276cd0..5237dda 100644
--- a/completions/ssh
+++ b/completions/ssh
@@ -115,13 +115,11 @@ _ssh_suboption_check()
 
 _ssh()
 {
-    local cur prev configfile
-    local -a config
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
-    #cur=`_get_cword :`
-    #prev=`_get_pword`
+    local configfile
+    local -a config
 
     _ssh_suboption_check && return 0
 
@@ -168,7 +166,7 @@ _ssh()
             -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) )
     else
         # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
-        set -- "${COMP_WORDS[@]}"
+        set -- "${words[@]}"
         while [ $# -gt 0 ]; do
             if [ "${1:0:2}" = -F ]; then
                 if [ ${#1} -gt 2 ]; then
@@ -182,7 +180,7 @@ _ssh()
             shift
         done
         _known_hosts_real -a -F "$configfile" "$cur"
-        if [ $COMP_CWORD -ne 1 ]; then
+        if [ $cword -ne 1 ]; then
             _compopt_o_filenames
             COMPREPLY+=( $( compgen -c -- "$cur" ) )
         fi
@@ -196,10 +194,10 @@ shopt -u hostcomplete && complete -F _ssh ssh slogin autossh
 #
 _sftp()
 {
-    local cur prev configfile
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local configfile
 
     _ssh_suboption_check && return 0
 
@@ -225,7 +223,7 @@ _sftp()
             -- "$cur" ) )
     else
         # Search COMP_WORDS for '-F configfile' argument
-        set -- "${COMP_WORDS[@]}"
+        set -- "${words[@]}"
         while [ $# -gt 0 ]; do
             if [ "${1:0:2}" = -F ]; then
                 if [ ${#1} -gt 2 ]; then
@@ -313,10 +311,10 @@ _scp_local_files()
 #
 _scp()
 {
-    local configfile cur prev prefix
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
+    local configfile prefix
 
     _ssh_suboption_check && {
         COMPREPLY=( "${COMPREPLY[@]/%/ }" )
@@ -355,7 +353,7 @@ _scp()
         prefix=-F
     else
         # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
-        set -- "${COMP_WORDS[@]}"
+        set -- "${words[@]}"
         while [ $# -gt 0 ]; do
             if [ "${1:0:2}" = -F ]; then
                 if [ ${#1} -gt 2 ]; then
@@ -395,10 +393,8 @@ complete -F _scp -o nospace scp
 #
 _ssh_copy_id()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -i)
diff --git a/completions/sshfs b/completions/sshfs
index c4d2edd..ce34d95 100644
--- a/completions/sshfs
+++ b/completions/sshfs
@@ -4,10 +4,10 @@ have sshfs || return
 
 _sshfs()
 {
-    local cur userhost path
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur
+    local userhost path
 
     _expand || return 0
 
diff --git a/completions/strace b/completions/strace
index 0637453..e7296ca 100644
--- a/completions/strace
+++ b/completions/strace
@@ -4,12 +4,13 @@ have strace || return
 
 _strace()
 {
-    local cur prev offset i syscalls arch unistd
+    local cur prev words cword
+    _init_completion || return
 
     # check if we're still completing strace
-    offset=0
-    for (( i=1; i <= COMP_CWORD; i++ )); do
-        case ${COMP_WORDS[$i]} in
+    local offset=0 i
+    for (( i=1; i <= cword; i++ )); do
+        case ${words[$i]} in
             -o|-e|-p)
                 i=$((i+1))
                 continue
@@ -26,9 +27,6 @@ _strace()
         _command_offset $offset
     else
 
-        COMPREPLY=()
-        _get_comp_words_by_ref cur prev
-
         case $prev in
             -e)
                 if [[ "$cur" == *=* ]]; then
@@ -37,11 +35,12 @@ _strace()
 
                     # Import arch-specific syscalls -- not foolproof IMHO
                     #+                                     --David Paleino
-                    arch=$(command uname -m)
-                    syscalls=$(awk '/^#define __NR/ {print $2}' \
+                    local arch=$(command uname -m)
+                    local syscalls=$(awk '/^#define __NR/ {print $2}' \
                         /usr/include/asm/unistd.h | sed -e \
                         's/__NR_//')
                     if [ -z "$syscalls" ]; then
+                        local unistd
                         if [[ "$arch" == *86 ]]; then
                             unistd=/usr/include/asm/unistd_32.h
                         else
diff --git a/completions/svk b/completions/svk
index 6d416be..d60e128 100644
--- a/completions/svk
+++ b/completions/svk
@@ -4,10 +4,10 @@ have svk || return
 
 _svk()
 {
-    local cur prev commands options command
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local commands options command
 
     commands='add admin annotate ann blame praise cat checkout co cleanup \
         cmerge cm commit ci copy cp delete del remove rm depotmap \
@@ -17,7 +17,7 @@ _svk()
         pset pull push resolved revert smerge sm status st stat switch \
         sw sync sy update up verify'
 
-    if [[ $COMP_CWORD -eq 1 ]] ; then
+    if [[ $cword -eq 1 ]] ; then
         if [[ "$cur" == -* ]]; then
             COMPREPLY=( $( compgen -W '--version' -- "$cur" ) )
         else
@@ -36,7 +36,7 @@ _svk()
                 ;;
         esac
 
-        command=${COMP_WORDS[1]}
+        command=${words[1]}
 
         if [[ "$cur" == -* ]]; then
             # possible options for the command
diff --git a/completions/sysbench b/completions/sysbench
index d55e689..215ca5e 100644
--- a/completions/sysbench
+++ b/completions/sysbench
@@ -8,12 +8,12 @@ have sysbench || return
 
 _sysbench()
 {
-    COMPREPLY=()
-    local cur prev words split=false
-    _get_comp_words_by_ref -n = cur prev words
+    local cur prev words cword
+    _init_completion -n = || return
 
     # long options need the "=" (whitespace split doesn't work), but we split
     # internally to make processing easier
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/sysctl b/completions/sysctl
index 13a9136..880ad9d 100644
--- a/completions/sysctl
+++ b/completions/sysctl
@@ -4,10 +4,8 @@ have sysctl || return
 
 _sysctl()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     COMPREPLY=( $( compgen -W \
         "$( PATH="$PATH:/sbin" sysctl -N -a 2>/dev/null )" -- "$cur" ) )
diff --git a/completions/sysv-rc b/completions/sysv-rc
index 94ca25a..6e480a4 100644
--- a/completions/sysv-rc
+++ b/completions/sysv-rc
@@ -5,9 +5,10 @@
 have update-rc.d &&
 _update_rc_d()
 {
-    local cur prev sysvdir services options valid_options
+    local cur prev words cword
+    _init_completion || return
 
-    _get_comp_words_by_ref cur prev
+    local sysvdir services options valid_options
 
     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
     || sysvdir=/etc/init.d
@@ -16,14 +17,14 @@ _update_rc_d()
     services=( ${services[@]#$sysvdir/} )
     options=( -f -n )
 
-    if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
+    if [[ $cword -eq 1 || "$prev" == -* ]]; then
     valid_options=( $( \
-        tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \
+        tr " " "\n" <<<"${words[@]} ${options[@]}" \
         | sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \
         | sort | uniq -u \
         ) )
     COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
-        -X '$( tr " " "|" <<<${COMP_WORDS[@]} )' -- "$cur" ) )
+        -X '$( tr " " "|" <<<${words[@]} )' -- "$cur" ) )
     elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]]; then
         COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) )
     elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
@@ -69,9 +70,10 @@ complete -F _update_rc_d update-rc.d
 have invoke-rc.d &&
 _invoke_rc_d()
 {
-    local cur prev sysvdir services options valid_options
+    local cur prev words cword
+    _init_completion || return
 
-    _get_comp_words_by_ref cur prev
+    local sysvdir services options valid_options
 
     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
     || sysvdir=/etc/init.d
@@ -81,9 +83,9 @@ _invoke_rc_d()
     options=( --help --quiet --force --try-anyway --disclose-deny --query \
         --no-fallback )
 
-    if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
+    if [[ ($cword -eq 1) || ("$prev" == --* ) ]]; then
     valid_options=( $( \
-        tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \
+        tr " " "\n" <<<"${words[@]} ${options[@]}" \
         | sed -ne "/$( sed "s/ /\\\\|/g" <<<"${options[@]}" )/p" \
         | sort | uniq -u \
         ) )
diff --git a/completions/tar b/completions/tar
index 1270b26..9d87578 100644
--- a/completions/tar
+++ b/completions/tar
@@ -4,10 +4,10 @@ have tar || return
 
 _tar()
 {
-    local cur prev words cword ext regex tar untar
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev words cword
+    local ext regex tar untar
 
     if [ $cword -eq 1 ]; then
         COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) )
@@ -65,7 +65,7 @@ _tar()
             # complete on files in tar file
             #
             # get name of tar file from command line
-            tar=$( sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' <<<"$COMP_LINE" )
+            tar=$( sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' <<<"${words[@]}" )
             # devise how to untar and list it
             untar=t${words[1]//[^IJzjyf]/}
 
diff --git a/completions/tcpdump b/completions/tcpdump
index e4bfdd9..cfed6fa 100644
--- a/completions/tcpdump
+++ b/completions/tcpdump
@@ -4,10 +4,8 @@ have tcpdump || return
 
 _tcpdump()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -r|-w|-F)
diff --git a/completions/unace b/completions/unace
index 3083410..17380c2 100644
--- a/completions/unace
+++ b/completions/unace
@@ -4,15 +4,13 @@ have unace || return
 
 _unace()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]] ; then
         COMPREPLY=( $( compgen -W '-c -c- -f -f- -o -o- -p -y -y-' -- "$cur" ) )
     else
-        if [ $COMP_CWORD -eq 1 ]; then
+        if [ $cword -eq 1 ]; then
             COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) )
         else
             _filedir ace
diff --git a/completions/unrar b/completions/unrar
index e561133..f83ef3b 100644
--- a/completions/unrar
+++ b/completions/unrar
@@ -4,17 +4,15 @@ have unrar || return
 
 _unrar()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]] ; then
         COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \
             -dh -ep -f -idp -ierr -inul -kb -o+ -o- -ow -p -p- -r -ta \
             -tb -tn -to -u -v -ver -vp -x -x@ -y' -- "$cur" ) )
     else
-        if [ $COMP_CWORD -eq 1 ]; then
+        if [ $cword -eq 1 ]; then
             COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- "$cur" ) )
         else
             _filedir rar
diff --git a/completions/update-alternatives b/completions/update-alternatives
index a4bdf96..5033cc5 100644
--- a/completions/update-alternatives
+++ b/completions/update-alternatives
@@ -9,9 +9,9 @@ _installed_alternatives()
     for i in alternatives dpkg/alternatives rpm/alternatives; do
         [ -d /var/lib/$i ] && admindir=/var/lib/$i && break
     done
-    for (( i=1; i < COMP_CWORD; i++ )); do
-        if [[ "${COMP_WORDS[i]}" == --admindir ]]; then
-            admindir=${COMP_WORDS[i+1]}
+    for (( i=1; i < cword; i++ )); do
+        if [[ "${words[i]}" == --admindir ]]; then
+            admindir=${words[i+1]}
             break
         fi
     done
@@ -20,10 +20,8 @@ _installed_alternatives()
 
 _update_alternatives()
 {
-    local cur prev mode args i
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --altdir|--admindir)
@@ -35,11 +33,13 @@ _update_alternatives()
             ;;
     esac
 
+    local mode args i
+
     # find which mode to use and how many real args used so far
-    for (( i=1; i < COMP_CWORD; i++ )); do
-        if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
-            mode=${COMP_WORDS[i]}
-            args=$(($COMP_CWORD - i))
+    for (( i=1; i < cword; i++ )); do
+        if [[ "${words[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
+            mode=${words[i]}
+            args=$(($cword - i))
             break
         fi
     done
diff --git a/completions/util-linux b/completions/util-linux
index 918363a..72b9776 100644
--- a/completions/util-linux
+++ b/completions/util-linux
@@ -5,16 +5,14 @@
 have renice &&
 _renice()
 {
-    local command cur curopt i
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
-    command=$1
+    local command=$1 curopt i=0
 
-    i=0
     # walk back through command line and find last option
-    while [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; do
-        curopt=${COMP_WORDS[COMP_CWORD-$i]}
+    while [[ $i -le $cword && ${#COMPREPLY[@]} -eq 0 ]]; do
+        curopt=${words[cword-$i]}
         case "$curopt" in
             -u)
                 _allowed_users
@@ -36,12 +34,10 @@ complete -F _renice renice
 have kill &&
 _kill()
 {
-    local cur
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
-
-    if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then
+    if [[ $cword -eq 1 && "$cur" == -* ]]; then
         # return list of available signals
         _signals
     else
@@ -56,12 +52,10 @@ complete -F _kill kill
 have look &&
 _look()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
-    if [[ $COMP_CWORD -eq 1 ]]; then
+    if [[ $cword -eq 1 ]]; then
         COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) )
     fi
 } &&
diff --git a/completions/vncviewer b/completions/vncviewer
index 296eb8a..dcfcab8 100644
--- a/completions/vncviewer
+++ b/completions/vncviewer
@@ -20,10 +20,8 @@ complete -F _vncviewer_bootstrap vncviewer
 have tightvncviewer &&
 _tightvncviewer()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -passwd)
@@ -61,10 +59,8 @@ complete -F _tightvncviewer tightvncviewer
 have xvnc4viewer &&
 _xvnc4viewer()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     # Convert double dash to single dash
     case ${prev/#--/-} in
diff --git a/completions/vpnc b/completions/vpnc
index 174b8f3..9cb35b7 100644
--- a/completions/vpnc
+++ b/completions/vpnc
@@ -4,10 +4,8 @@ have vpnc || return
 
 _vpnc()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --pfs)
diff --git a/completions/wireless-tools b/completions/wireless-tools
index 13a82d6..75c348c 100644
--- a/completions/wireless-tools
+++ b/completions/wireless-tools
@@ -5,10 +5,8 @@
 have iwconfig &&
 _iwconfig()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         mode)
@@ -20,7 +18,7 @@ _iwconfig()
             COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
                 COMPREPLY+=( $( compgen -W \
-                    "$( iwlist ${COMP_WORDS[1]} scan | \
+                    "$( iwlist ${words[1]} scan | \
                     awk -F'\"' '/ESSID/ {print $2}' )" -- "$cur" ) )
             fi
             return 0
@@ -30,13 +28,13 @@ _iwconfig()
             return 0
             ;;
         channel)
-            COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \
+            COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \
                 awk '/^[ \t]*Channel/ {print $2}' )" -- "$cur" ) )
             return 0
             ;;
 
         freq)
-            COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \
+            COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \
                 awk '/^[ \t]*Channel/ {print $4"G"}')" -- "$cur" ) )
             return 0
             ;;
@@ -44,7 +42,7 @@ _iwconfig()
             COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
                 COMPREPLY+=( $( compgen -W \
-                    "$( iwlist ${COMP_WORDS[1]} scan | \
+                    "$( iwlist ${words[1]} scan | \
                     awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) )
             fi
             return 0
@@ -52,7 +50,7 @@ _iwconfig()
         rate)
             COMPREPLY=( $( compgen -W 'auto fixed' -- "$cur" ) )
             COMPREPLY+=( $( compgen -W \
-                "$( iwlist ${COMP_WORDS[1]} rate | \
+                "$( iwlist ${words[1]} rate | \
                 awk '/^[ \t]*[0-9]/ {print $1"M"}' )" -- "$cur" ) )
             return 0
             ;;
@@ -78,7 +76,7 @@ _iwconfig()
             ;;
     esac
 
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         if [[ "$cur" == -* ]]; then
             COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
         else
@@ -96,12 +94,10 @@ complete -F _iwconfig iwconfig
 have iwlist &&
 _iwlist()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         if [[ "$cur" == -* ]]; then
             COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
         else
@@ -119,12 +115,10 @@ complete -F _iwlist iwlist
 have iwspy &&
 _iwspy()
 {
-    local cur
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
-
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         if [[ "$cur" == -* ]]; then
             COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
         else
@@ -140,10 +134,8 @@ complete -F _iwspy iwspy
 have iwpriv &&
 _iwpriv()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         roam)
@@ -156,7 +148,7 @@ _iwpriv()
             ;;
     esac
 
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         if [[ "$cur" == -* ]]; then
             COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
         else
diff --git a/completions/wodim b/completions/wodim
index 8ccfcd8..4e64465 100644
--- a/completions/wodim
+++ b/completions/wodim
@@ -8,10 +8,10 @@ have cdrecord || have wodim || return
 
 _cdrecord()
 {
-    local cur prev i generic_options track_options track_mode
+    local cur prev words cword
+    _init_completion -n = || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n = cur prev
+    local i generic_options track_options track_mode
 
     # foo=bar style option
     if [[ "$cur" == *=* ]]; then
@@ -82,7 +82,7 @@ _cdrecord()
         -copy -nocopy -scms isrc= index= padsize= pregap= tsize= )
     # look if previous was either a file or a track option
     track_mode=0
-    if [ $COMP_CWORD -gt 1 ]; then
+    if [ $cword -gt 1 ]; then
         if [ -f "$prev" ]; then
             track_mode=1
         else
diff --git a/completions/wol b/completions/wol
index 3e663ac..ce8e629 100644
--- a/completions/wol
+++ b/completions/wol
@@ -4,9 +4,10 @@ have wol || return
 
 _wol()
 {
-    local cur prev split=false
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
+    local cur prev words cword
+    _init_completion -n : || return
+
+    local split=false
     _split_longopt && split=true
 
     case $prev in
diff --git a/completions/wtf b/completions/wtf
index d68b6ba..e34c769 100644
--- a/completions/wtf
+++ b/completions/wtf
@@ -5,15 +5,15 @@ have wtf || return
 
 _wtf()
 {
-    local cur prev db
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     [ "$prev" = -f ] && _filedir && return 0
     [[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0
 
-    set -- "${COMP_WORDS[@]}"
+    local db
+
+    set -- "${words[@]}"
     while [ $# -gt 0 ]; do
         if [ "$1" = -f ]; then
             shift ; db=$1 ; break
diff --git a/completions/wvdial b/completions/wvdial
index bc7e59b..78ae25f 100644
--- a/completions/wvdial
+++ b/completions/wvdial
@@ -4,10 +4,8 @@ have wvdial || return
 
 _wvdial()
 {
-    local cur prev config i IFS=$'\n'
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --config)
@@ -16,6 +14,8 @@ _wvdial()
             ;;
     esac
 
+    local config i IFS=$'\n'
+
     case $cur in
         -*)
             COMPREPLY=( $( compgen -W '--config --chat \
@@ -26,9 +26,9 @@ _wvdial()
             # start with global and personal config files
             config="/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc"
             # replace with command line config file if present
-            for (( i=1; i < COMP_CWORD; i++ )); do
-                if [[ "${COMP_WORDS[i]}" == "--config" ]]; then
-                    config=${COMP_WORDS[i+1]}
+            for (( i=1; i < cword; i++ )); do
+                if [[ "${words[i]}" == "--config" ]]; then
+                    config=${words[i+1]}
                     break
                 fi
             done
diff --git a/completions/xhost b/completions/xhost
index 0476afe..2cbabe8 100644
--- a/completions/xhost
+++ b/completions/xhost
@@ -4,8 +4,8 @@ have xhost || return
 
 _xhost ()
 {
-    local cur
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     case $cur in
         +*) _known_hosts_real -p+ "${cur:1}" ;;
diff --git a/completions/xm b/completions/xm
index 1ec2cbf..dfed983 100644
--- a/completions/xm
+++ b/completions/xm
@@ -16,12 +16,12 @@ _xen_domain_ids()
 
 _xm()
 {
-    # TODO: _split_longopt
+    local cur prev words cword
+    _init_completion || return
 
-    local cur prev command options
+    # TODO: _split_longopt
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local command options
 
     commands='console vncviewer create new delete destroy domid domname \
         dump-core list mem-max mem-set migrate pause reboot rename reset \
@@ -34,7 +34,7 @@ _xm()
         labels addlabel rmlabel getlabel dry-run resources dumppolicy \
         setpolicy resetpolicy getpolicy shell help'
 
-    if [[ $COMP_CWORD -eq 1 ]] ; then
+    if [[ $cword -eq 1 ]] ; then
         COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
     else
         if [[ "$cur" == *=* ]]; then
@@ -42,7 +42,7 @@ _xm()
             cur=${cur/*=/}
         fi
 
-        command=${COMP_WORDS[1]}
+        command=${words[1]}
         if [[ "$cur" == -* ]]; then
             # possible options for the command
             case $command in
diff --git a/completions/xmllint b/completions/xmllint
index 7e83296..8095dae 100644
--- a/completions/xmllint
+++ b/completions/xmllint
@@ -4,10 +4,8 @@ have xmllint || return
 
 _xmllint()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -o|--output)
diff --git a/completions/xmlwf b/completions/xmlwf
index 0df6404..71fbb73 100644
--- a/completions/xmlwf
+++ b/completions/xmlwf
@@ -4,10 +4,8 @@ have xmlwf || return
 
 _xmlwf()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -d)
diff --git a/completions/xmms b/completions/xmms
index cb031da..82473b0 100644
--- a/completions/xmms
+++ b/completions/xmms
@@ -4,10 +4,8 @@ have xmms || return
 
 _xmms()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \
diff --git a/completions/xmodmap b/completions/xmodmap
index dfa6741..595b26e 100644
--- a/completions/xmodmap
+++ b/completions/xmodmap
@@ -4,9 +4,8 @@ have xmodmap || return
 
 _xmodmap()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -display|-e)
diff --git a/completions/xrandr b/completions/xrandr
index b1747e6..6c929a6 100644
--- a/completions/xrandr
+++ b/completions/xrandr
@@ -4,9 +4,10 @@ have xrandr || return
 
 _xrandr()
 {
-    local cur prev output modes
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
+
+    local output modes
 
     case $prev in
         --output)
@@ -15,9 +16,9 @@ _xrandr()
             return 0
             ;;
         --mode)
-            for(( i = 1; i < COMP_CWORD; i++ )); do
-                if [[ "${COMP_WORDS[i]}" == "--output" ]]; then
-                    output=${COMP_WORDS[i+1]}
+            for(( i = 1; i < cword; i++ )); do
+                if [[ "${words[i]}" == "--output" ]]; then
+                    output=${words[i+1]}
                     break
                 fi
             done
diff --git a/completions/xrdb b/completions/xrdb
index 77d6889..b42320f 100644
--- a/completions/xrdb
+++ b/completions/xrdb
@@ -4,9 +4,8 @@ have xrdb || return
 
 _xrdb()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -backup|-display|-help)
diff --git a/completions/xsltproc b/completions/xsltproc
index 6b837c0..32efcab 100644
--- a/completions/xsltproc
+++ b/completions/xsltproc
@@ -4,9 +4,8 @@ have xsltproc || return
 
 _xsltproc()
 {
-    local cur prev
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
 	--output|-o)
@@ -37,7 +36,7 @@ _xsltproc()
             ;;
     esac
 
-    [[ $COMP_CWORD -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \
+    [[ $cword -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \
         return 0
 
     if [[ "$cur" == -* ]]; then
diff --git a/completions/xz b/completions/xz
index 45fc0d3..8a4fc5e 100644
--- a/completions/xz
+++ b/completions/xz
@@ -3,9 +3,8 @@
 have xz || have pxz &&
 _xz()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '--compress --decompress --test --list \
@@ -64,9 +63,8 @@ complete -F _xz xz pxz
 have xzdec &&
 _xzdec()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '--memory --quiet --help --version' \
diff --git a/completions/yp-tools b/completions/yp-tools
index 856c2c2..f777a5b 100644
--- a/completions/yp-tools
+++ b/completions/yp-tools
@@ -4,22 +4,20 @@ have ypcat || return
 
 _ypmatch()
 {
-    local cur map cmd
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
-    cmd=${1##*/}
+    local map cmd=${1##*/}
 
-    [[ $cmd == ypcat && $COMP_CWORD -gt 1 ]] && return 0
-    [[ $cmd == ypmatch && $COMP_CWORD -gt 2 ]] && return 0
+    [[ $cmd == ypcat && $cword -gt 1 ]] && return 0
+    [[ $cmd == ypmatch && $cword -gt 2 ]] && return 0
 
-    if [[ $cmd == ypmatch && $COMP_CWORD -eq 1 && \
-        ${#COMP_WORDS[@]} -eq 3 ]]; then
-        map=${COMP_WORDS[2]}
+    if [[ $cmd == ypmatch && $cword -eq 1 && ${#words[@]} -eq 3 ]]; then
+        map=${words[2]}
         COMPREPLY=( $( compgen -W '$( ypcat $map | \
             cut -d':' -f 1 )' -- "$cur") )
     else
-        [[ $cmd == ypmatch && $COMP_CWORD -ne 2 ]] && return 0
+        [[ $cmd == ypmatch && $cword -ne 2 ]] && return 0
         COMPREPLY=( $( compgen -W \
             '$( printf "%s\n" $(ypcat -x | cut -d"\"" -f 2) )' -- "$cur"))
     fi
diff --git a/completions/yum-arch b/completions/yum-arch
index 7fc5ed3..eb02b92 100644
--- a/completions/yum-arch
+++ b/completions/yum-arch
@@ -4,9 +4,8 @@ have yum-arch || return
 
 _yum_arch()
 {
-    local cur
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]] ; then
         COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- "$cur" ) )

-- 
bash-completion



More information about the Bash-completion-commits mailing list