[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-99-ge3ca91b

Ville Skyttä ville.skytta at iki.fi
Wed Apr 20 20:14:31 UTC 2011


The following commit has been merged in the master branch:
commit e3ca91b9866e60ac541c9a1cf065b855a1681bc3
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Wed Apr 20 23:08:37 2011 +0300

    Use _init_completion() in completions/p*.

diff --git a/completions/p4 b/completions/p4
index 5a5d856..d18b679 100644
--- a/completions/p4
+++ b/completions/p4
@@ -4,10 +4,10 @@ have p4 || return
 
 _p4()
 {
-    local cur prev words cword p4commands p4filetypes
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev words cword
+    local p4commands p4filetypes
 
     # rename isn't really a command
     p4commands="$( p4 help commands | awk 'NF>3 {print $1}' )"
diff --git a/completions/perl b/completions/perl
index 1ded7cb..dcf5d5b 100644
--- a/completions/perl
+++ b/completions/perl
@@ -19,12 +19,10 @@ _perlfunctions()
 
 _perl()
 {
-    local cur prev prefix temp
-    local optPrefix optSuffix
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
-    prefix=""
+    local prefix="" temp optPrefix optSuffix
 
     # If option not followed by whitespace, reassign prev and cur
     if [[ "$cur" == -?* ]]; then
@@ -87,11 +85,10 @@ complete -F _perl perl
 
 _perldoc()
 {
-    local cur prev prefix temp
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
-    prefix=""
+    local prefix="" temp
 
     # completing an option (may or may not be separated by a space)
     if [[ "$cur" == -?* ]]; then
diff --git a/completions/pine b/completions/pine
index 41a9834..a8f1573 100644
--- a/completions/pine
+++ b/completions/pine
@@ -4,10 +4,8 @@ have pine || have alpine || return
 
 _pineaddr()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook \
         2>/dev/null)' -- "$cur" ) )
diff --git a/completions/pkg-config b/completions/pkg-config
index 24edac6..4d21af4 100644
--- a/completions/pkg-config
+++ b/completions/pkg-config
@@ -4,11 +4,10 @@ have pkg-config || return
 
 _pkg_config()
 {
-    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/pkg_install b/completions/pkg_install
index 95a17ac..5254555 100644
--- a/completions/pkg_install
+++ b/completions/pkg_install
@@ -4,10 +4,10 @@
 
 _pkg_delete()
 {
-    local cur pkgdir prev
+    local cur prev words cword
+    _init_completion || return
 
-    pkgdir=${PKG_DBDIR:-/var/db/pkg}/
-    _get_comp_words_by_ref cur prev
+    local pkgdir=${PKG_DBDIR:-/var/db/pkg}/
 
     [[ "$prev" == -o || "$prev" == -p || "$prev" == -W ]] && return 0
 
diff --git a/completions/pkgtools b/completions/pkgtools
index 4cb8d09..3ef913f 100644
--- a/completions/pkgtools
+++ b/completions/pkgtools
@@ -4,10 +4,8 @@
 
 _removepkg()
 {
-    local packages cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) )
 } &&
diff --git a/completions/pm-utils b/completions/pm-utils
index 4deb82e..3d4f2fe 100644
--- a/completions/pm-utils
+++ b/completions/pm-utils
@@ -3,8 +3,9 @@
 have pm-is-supported &&
 _pm_is_supported()
 {
-    local cur
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
+
     COMPREPLY=( $( compgen -W '--help --suspend --hibernate --suspend-hybrid' \
         -- "$cur" ) )
 } &&
@@ -13,8 +14,9 @@ complete -F _pm_is_supported pm-is-supported
 have pm-hibernate || have pm-suspend || have pm-suspend-hybrid &&
 _pm_action()
 {
-    local cur
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
+
     COMPREPLY=( $( compgen -W "--help $( _parse_help "$1" )" -- "$cur" ) )
 } &&
 complete -F _pm_action pm-hibernate pm-suspend pm-suspend-hybrid
@@ -22,8 +24,9 @@ complete -F _pm_action pm-hibernate pm-suspend pm-suspend-hybrid
 have pm-powersave &&
 _pm_powersave()
 {
-    local cur
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
+
     COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
 } &&
 complete -F _pm_powersave pm-powersave
diff --git a/completions/portupgrade b/completions/portupgrade
index d4b2687..be3be91 100644
--- a/completions/portupgrade
+++ b/completions/portupgrade
@@ -3,13 +3,13 @@
 have portupgrade &&
 _portupgrade()
 {
-    local cur pkgdir prev
-
-    pkgdir=${PKG_DBDIR:-/var/db/pkg}/
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     [[ "$prev" == -l || "$prev" == -L || "$prev" == -o ]] && return 0
 
+    local pkgdir=${PKG_DBDIR:-/var/db/pkg}/
+
     COMPREPLY=( $( compgen -d "$pkgdir$cur" ) )
     COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
     COMPREPLY=( ${COMPREPLY[@]%-*} )
@@ -21,7 +21,10 @@ complete -F _portupgrade -o dirnames portupgrade
 have portinstall &&
 _portinstall()
 {
-    local cur portsdir prev indexfile
+    local cur prev words cword
+    _init_completion || return
+
+    local portsdir indexfile
     local -a COMPREPLY2
 
     portsdir=${PORTSDIR:-/usr/ports}/
diff --git a/completions/postfix b/completions/postfix
index b2e0b83..c52f9e1 100644
--- a/completions/postfix
+++ b/completions/postfix
@@ -6,10 +6,8 @@ have postfix || return
 #
 _postfix()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -c)
@@ -36,10 +34,8 @@ complete -F _postfix postfix
 #
 _postmap()
 {
-    local cur prev len idx
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -c)
@@ -61,8 +57,7 @@ _postmap()
         _compopt_o_filenames
         COMPREPLY=( $( compgen -f -- "${cur#*:}" ) )
     else
-        len=${#cur}
-        idx=0
+        local len=${#cur} idx=0 pval
         for pval in $( /usr/sbin/postconf -m ); do
             if [[ "$cur" == "${pval:0:$len}" ]]; then
                 COMPREPLY[$idx]="$pval:"
@@ -82,10 +77,8 @@ complete -F _postmap postmap postalias
 #
 _postcat()
 {
-    local cur prev pval len idx qfile
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -c)
@@ -99,12 +92,12 @@ _postcat()
         return 0
     fi
 
-    qfile=0
-    for idx in "${COMP_WORDS[@]}"; do
+    local idx qfile=0
+    for idx in "${words[@]}"; do
         [[ "$idx" = -q ]] && qfile=1 && break
     done
     if [[ $qfile -eq 1 ]]; then
-        len=${#cur}
+        local len=${#cur} pval
         idx=0
         for pval in $( mailq 2>/dev/null | \
             sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//' ); do
@@ -125,10 +118,10 @@ complete -F _postcat postcat
 #
 _postconf()
 {
-    local cur prev pval len idx eqext
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local eqext
 
     case $prev in
         -b|-t)
@@ -151,8 +144,7 @@ _postconf()
         return 0
     fi
 
-    len=${#cur}
-    idx=0
+    local len=${#cur} idx=0 pval
     for pval in $( /usr/sbin/postconf 2>/dev/null | cut -d ' ' -f 1 ); do
         if [[ "$cur" == "${pval:0:$len}" ]]; then
             COMPREPLY[$idx]="$pval$eqext"
@@ -167,10 +159,10 @@ complete -F _postconf postconf
 #
 _postsuper()
 {
-    local cur prev pval len idx
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local pval len idx
 
     case $prev in
         -c)
diff --git a/completions/postgresql b/completions/postgresql
index c0e80b6..239c92f 100644
--- a/completions/postgresql
+++ b/completions/postgresql
@@ -22,11 +22,10 @@ _pg_users()
 #
 _createdb()
 {
-    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
@@ -64,11 +63,10 @@ complete -F _createdb -o default createdb
 #
 _dropdb()
 {
-    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 _dropdb -o default dropdb
 #
 _psql()
 {
-    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/povray b/completions/povray
index b5ba4c0..c663ed0 100644
--- a/completions/povray
+++ b/completions/povray
@@ -4,11 +4,11 @@ have povray || have xpovray || have spovray || return
 
 _povray()
 {
-    local cur prev povcur pfx oext defoext
-    defoext=png # default output extension, if cannot be determined FIXME
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -c povcur prev
+    local povcur=$cur pfx oext defoext
+    defoext=png # default output extension, if cannot be determined FIXME
 
     _expand || return 0
 
@@ -22,14 +22,14 @@ _povray()
             ;;
         [-+]O*)
             # guess what output file type user may want
-            case $( ( IFS=$'\n'; command grep '^[-+]F' <<<"${COMP_WORDS[*]}" ) ) in
+            case $( ( IFS=$'\n'; command grep '^[-+]F' <<<"${words[*]}" ) ) in
                 [-+]FN) oext=png ;;
                 [-+]FP) oext=ppm ;;
                 [-+]F[CT]) oext=tga ;;
                 *) oext=$defoext ;;
             esac
             # complete filename corresponding to previously specified +I
-            COMPREPLY=( $( ( IFS=$'\n'; command grep '^[-+]I' <<<"${COMP_WORDS[*]}" ) ) )
+            COMPREPLY=( $( ( IFS=$'\n'; command grep '^[-+]I' <<<"${words[*]}" ) ) )
             COMPREPLY=( ${COMPREPLY[@]#[-+]I} )
             COMPREPLY=( ${COMPREPLY[@]/%.pov/.$oext} )
             cur="${povcur#[-+]O}" # to confuse _filedir
@@ -49,7 +49,6 @@ _povray()
             return 0
             ;;
         *)
-            cur="$povcur"
             _filedir '@(ini|pov)'
             return 0
             ;;
diff --git a/completions/procps b/completions/procps
index db8fc3d..0810468 100644
--- a/completions/procps
+++ b/completions/procps
@@ -5,12 +5,10 @@
 [[ $UNAME == Linux || $UNAME == FreeBSD ]] || have pkill &&
 _killall()
 {
-    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
         _signals
     else
         _pnames
@@ -26,10 +24,8 @@ have pkill && complete -F _killall pkill
 [ $UNAME = Linux ] || have pgrep &&
 _pgrep()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     _pnames
 
diff --git a/completions/puppet b/completions/puppet
index bebf4fb..fe4a3d3 100644
--- a/completions/puppet
+++ b/completions/puppet
@@ -50,10 +50,10 @@ _puppet_references()
 
 _puppet()
 {
-    local cur prev xspec helpopts command subcommand
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local xspec helpopts command subcommand
 
     case $prev in
         --help)
@@ -61,7 +61,7 @@ _puppet()
             ;;
     esac
 
-    case ${COMP_WORDS[0]} in
+    case ${words[0]} in
         puppetmasterd)
             command=master
             ;;
@@ -90,9 +90,9 @@ _puppet()
             command=describe
             ;;
         puppet)
-            case ${COMP_WORDS[1]} in
+            case ${words[1]} in
                agent|apply|cert|describe|doc|filebucket|kick|master|queue|resource)
-                   command=${COMP_WORDS[1]}
+                   command=${words[1]}
                    ;;
                *.pp|*.rb|-*)
                    command=apply
diff --git a/completions/python b/completions/python
index badff32..b0a93e1 100644
--- a/completions/python
+++ b/completions/python
@@ -4,10 +4,8 @@ have python || return
 
 _python()
 {
-    local prev cur i
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -'?'|-h|--help|-V|--version|-c|-m)
@@ -23,15 +21,16 @@ _python()
             return 0
             ;;
         !(?(*/)python*([0-9.])|-?))
-            [[ $COMP_CWORD -lt 2 || ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] \
+            [[ $cword -lt 2 || ${words[cword-2]} != -@(Q|W) ]] \
                 && _filedir
             ;;
     esac
 
 
     # if '-c' is already given, complete all kind of files.
-    for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
-        if [[ ${COMP_WORDS[i]} == -c ]]; then
+    local i
+    for (( i=0; i < ${#words[@]}-1; i++ )); do
+        if [[ ${words[i]} == -c ]]; then
             _filedir
         fi
     done

-- 
bash-completion



More information about the Bash-completion-commits mailing list