[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-84-g4c97896

Ville Skyttä ville.skytta at iki.fi
Wed Apr 20 11:42:52 UTC 2011


The following commit has been merged in the master branch:
commit 4c9789605fdd221e1d60d863c537b5f2782aa296
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Wed Apr 20 14:42:30 2011 +0300

    Use _init_completion() in completions/c*.

diff --git a/CHANGES b/CHANGES
index 298357b..3c216ed 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,7 +15,7 @@ bash-completion (2.x)
   * Support tildes when recursively sourcing muttrc files (Debian: #615134).
   * Fix local variable leaks from various completions.
   * Add _init_completion() for common completion initialization and generic
-    redirection handling.
+    redirection handling, use it in many completions.
 
   [ Guillaume Rousse ]
   * added puppet completion, using work from Mathieu Parent (sathieudebian.org)
diff --git a/completions/cardctl b/completions/cardctl
index 9d817e2..da95f6d 100644
--- a/completions/cardctl
+++ b/completions/cardctl
@@ -4,12 +4,10 @@ have cardctl || have pccardctl || return
 
 _cardctl()
 {
-    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
         COMPREPLY=( $( compgen -W 'status config ident suspend \
             resume reset eject insert scheme' -- "$cur" ) )
     fi
diff --git a/completions/cfengine b/completions/cfengine
index 70b152b..5470fbd 100644
--- a/completions/cfengine
+++ b/completions/cfengine
@@ -15,10 +15,8 @@ _cfagent_options()
 
 _cfagent()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -f|--file)
@@ -35,14 +33,12 @@ complete -F _cfagent cfagent
 
 _cfrun()
 {
-    local i section cfinputs cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
-    section=1
-    for (( i=1; i < COMP_CWORD; i++ )); do
-        if [[ "${COMP_WORDS[i]}" == -- ]]; then
+    local i section=1
+    for (( i=1; i < cword; i++ )); do
+        if [[ "${words[i]}" == -- ]]; then
             section=$((section + 1))
         fi
     done
@@ -60,9 +56,9 @@ _cfrun()
                 COMPREPLY=( $( compgen -W '-f -h -d -S -T -v' -- $cur ) )
             else
                 hostfile=${CFINPUTS:-/var/lib/cfengine/inputs}/cfrun.hosts
-                for (( i=1; i < COMP_CWORD; i++ )); do
-                    if [[ "${COMP_WORDS[i]}" == -f ]]; then
-                        hostfile=${COMP_WORDS[i+1]}
+                for (( i=1; i < cword; i++ )); do
+                    if [[ "${words[i]}" == -f ]]; then
+                        hostfile=${words[i+1]}
                         break
                     fi
                 done
diff --git a/completions/chkconfig b/completions/chkconfig
index 5424520..941890a 100644
--- a/completions/chkconfig
+++ b/completions/chkconfig
@@ -4,11 +4,10 @@ have chkconfig || return
 
 _chkconfig()
 {
-    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
@@ -27,7 +26,7 @@ _chkconfig()
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '--list --add --del --override --level' -- "$cur" ) )
     else
-        if [[ $COMP_CWORD -eq 2 || $COMP_CWORD -eq 4 ]]; then
+        if [[ $cword -eq 2 || $cword -eq 4 ]]; then
             COMPREPLY=( $( compgen -W 'on off reset resetpriorities' -- "$cur" ) )
         else
             _services
diff --git a/completions/chsh b/completions/chsh
index 2aa0bfa..5bf01ec 100644
--- a/completions/chsh
+++ b/completions/chsh
@@ -4,10 +4,8 @@ have chsh || return
 
 _chsh()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --list-shells|--help|-v|--version)
diff --git a/completions/cksfv b/completions/cksfv
index 629d026..921afb0 100644
--- a/completions/cksfv
+++ b/completions/cksfv
@@ -4,12 +4,10 @@ have cksfv || return
 
 _cksfv()
 {
-    local cur prev
+    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
         COMPREPLY=( $( compgen -W '-C -f -i -q -v' -- "$cur" ) )
         return 0
     fi
diff --git a/completions/clisp b/completions/clisp
index b0eec52..dc0f2cd 100644
--- a/completions/clisp
+++ b/completions/clisp
@@ -5,10 +5,8 @@ have clisp || return
 
 _clisp()
 {
-    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/configure b/completions/configure
index 4f8e03c..a8afb1c 100644
--- a/completions/configure
+++ b/completions/configure
@@ -4,11 +4,10 @@
 
 _configure()
 {
-    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/coreutils b/completions/coreutils
index 490eaf9..97fe96a 100644
--- a/completions/coreutils
+++ b/completions/coreutils
@@ -5,11 +5,11 @@
 have chown &&
 _chown()
 {
-    local cur prev split=false
-
-    # Get cur and prev words; but don't treat user:group as separate words.
-    _get_comp_words_by_ref -n : cur prev
+    local cur prev words cword
+    # Don't treat user:group as separate words.
+    _init_completion -n : || return
 
+    local split=false
     _split_longopt && split=true
 
     case "$prev" in
@@ -28,7 +28,7 @@ _chown()
     if [[ "$cur" == -* ]]; then
         # Complete -options
         local w opts
-        for w in "${COMP_WORDS[@]}" ; do
+        for w in "${words[@]}" ; do
             [[ "$w" == -@(R|-recursive) ]] && opts="-H -L -P" && break
         done
         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
@@ -55,12 +55,12 @@ complete -F _chown chown
 have chgrp &&
 _chgrp()
 {
-    local cur prev split=false
+    local cur prev words cword
+    _init_completion || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
     cur=${cur//\\\\/}
 
+    local split=false
     _split_longopt && split=true
 
     if [[ "$prev" == --reference ]]; then
@@ -73,7 +73,7 @@ _chgrp()
     # options completion
     if [[ "$cur" == -* ]]; then
         local w opts
-        for w in "${COMP_WORDS[@]}" ; do
+        for w in "${words[@]}" ; do
             [[ "$w" == -@(R|-recursive) ]] && opts="-H -L -P" && break
         done
         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
@@ -83,7 +83,7 @@ _chgrp()
     fi
 
     # first parameter on line or first since an option?
-    if [[ $COMP_CWORD -eq 1 && "$cur" != -* || "$prev" == -* ]]; then
+    if [[ $cword -eq 1 && "$cur" != -* || "$prev" == -* ]]; then
         _allowed_groups "$cur"
     else
         _filedir || return 0
@@ -98,10 +98,8 @@ complete -F _chgrp chgrp
 have id &&
 _id()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     if [[ "$cur" == -* ]]; then
         COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\
@@ -117,10 +115,10 @@ complete -F _id id
 have mktemp &&
 _mktemp()
 {
-    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/cowsay b/completions/cowsay
index 588b239..723a236 100644
--- a/completions/cowsay
+++ b/completions/cowsay
@@ -4,10 +4,8 @@ have cowsay || return
 
 _cowsay()
 {
-    local cur prev
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -f)
diff --git a/completions/cpan2dist b/completions/cpan2dist
index 63c0c59..6b4b6db 100644
--- a/completions/cpan2dist
+++ b/completions/cpan2dist
@@ -4,10 +4,8 @@ have cpan2dist || return
 
 _cpan2dist()
 {
-    local cur prev packagelist cpandirs
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --format)
@@ -32,7 +30,8 @@ _cpan2dist()
             --set-program --dist-opts --default-banlist \
             --default-ignorelist' -- $cur ) )
     else
-        cpandirs=( "$HOME/.cpanplus/" "$HOME/.cpan/source/modules/" )
+        local cpandirs=( "$HOME/.cpanplus/" "$HOME/.cpan/source/modules/" )
+        local packagelist
         for dir in ${cpandirs[@]}; do
             [[ -d "$dir" && -r "$dir/02packages.details.txt.gz" ]] && \
                 packagelist="$dir/02packages.details.txt.gz"
diff --git a/completions/cpio b/completions/cpio
index 3b464ed..995ca86 100644
--- a/completions/cpio
+++ b/completions/cpio
@@ -9,11 +9,10 @@ _cpio_format()
 
 _cpio()
 {
-    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
 
     # --name value style option
@@ -39,11 +38,11 @@ _cpio()
 
     $split && return 0
 
-    if [ $COMP_CWORD -eq 1 ]; then
+    if [ $cword -eq 1 ]; then
         COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through \
                                    -? --help --license --usage --version' -- "$cur" ) )
     else
-        case ${COMP_WORDS[1]} in
+        case ${words[1]} in
             -o|--create)
                 if [[ "$cur" == -* ]]; then
                     COMPREPLY=( $( compgen -W '-0 -a -c -v -A -B\
diff --git a/completions/crontab b/completions/crontab
index a10d2b4..2cad852 100644
--- a/completions/crontab
+++ b/completions/crontab
@@ -4,9 +4,8 @@ have crontab || return
 
 _crontab()
 {
-    local cur prev
-    COMPREPLY=()
-    _get_comp_words_by_ref cur prev
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         -u)
@@ -18,8 +17,8 @@ _crontab()
     local i opts=" -u -l -r -e" # leading space at start is significant...
     [[ $OSTYPE == *linux* ]] && opts+=" -i"
     [ -e /etc/selinux ] && opts+=" -s"
-    for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
-        case "${COMP_WORDS[i]}" in
+    for (( i=0; i < ${#words[@]}-1; i++ )); do
+        case "${words[i]}" in
             -l)
                 opts=${opts// -l -r -e/}
                 opts=${opts// -i/}
@@ -37,7 +36,7 @@ _crontab()
                 opts=${opts// -i/}
                 ;;
             -i|-s)
-                opts=${opts// ${COMP_WORDS[i]}/}
+                opts=${opts// ${words[i]}/}
                 ;;
         esac
     done
@@ -48,7 +47,7 @@ _crontab()
     fi
 
     # do filenames only if we did not have -l, -r, or -e
-    [[ "${COMP_LINE}" == *\ -@(l|r|e)* ]] || _filedir
+    [[ "${words[@]}" == *\ -@(l|r|e)* ]] || _filedir
 } &&
 complete -F _crontab crontab
 
diff --git a/completions/cryptsetup b/completions/cryptsetup
index b2fafcb..46f1e48 100644
--- a/completions/cryptsetup
+++ b/completions/cryptsetup
@@ -16,10 +16,8 @@ _cryptsetup_device()
 
 _cryptsetup()
 {
-    local cur prev arg
-    COMPREPLY=()
-    cur=`_get_cword`
-    prev=`_get_pword`
+    local cur prev words cword
+    _init_completion || return
 
     case $prev in
         --key-file|--master-key-file|--header-backup-file|-d)
@@ -28,6 +26,7 @@ _cryptsetup()
             ;;
     esac
 
+    local arg
     _get_first_arg
     if [ -z $arg ]; then
         if [[ "$cur" == -* ]]; then
diff --git a/completions/cups b/completions/cups
index 1aa4f93..6ba7bff 100644
--- a/completions/cups
+++ b/completions/cups
@@ -4,10 +4,8 @@ have cancel || return
 
 _cancel()
 {
-    local cur
-
-    COMPREPLY=()
-    _get_comp_words_by_ref cur
+    local cur prev words cword
+    _init_completion || return
 
     COMPREPLY=( $( compgen -W "$( lpstat | cut -d' ' -f1 )" -- "$cur" ) )
 } &&
diff --git a/completions/cvs b/completions/cvs
index ec6c344..2e47861 100644
--- a/completions/cvs
+++ b/completions/cvs
@@ -57,17 +57,17 @@ _cvs_roots()
 
 _cvs()
 {
-    local cur prev count mode i cvsroot cvsroots pwd
-    local -a flags miss files entries changed newremoved
+    local cur prev words cword
+    _init_completion -n : || return
 
-    COMPREPLY=()
-    _get_comp_words_by_ref -n : cur prev
+    local count mode i cvsroot cvsroots pwd
+    local -a flags miss files entries changed newremoved
 
     count=0
-    for i in "${COMP_WORDS[@]}"; do
-        [ $count -eq $COMP_CWORD ] && break
+    for i in "${words[@]}"; do
+        [ $count -eq $cword ] && break
         # Last parameter was the CVSROOT, now go back to mode selection
-        if [[ "${COMP_WORDS[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
+        if [[ "${words[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
             mode=""
         fi
         if [ -z "$mode" ]; then
@@ -78,7 +78,7 @@ _cvs()
                     ;;
                 -d)
                     mode=cvsroot
-                    cvsroot=${COMP_WORDS[((count+1))]}
+                    cvsroot=${words[((count+1))]}
                     ;;
                 ad|add|new)
                     mode=add
@@ -155,7 +155,7 @@ _cvs()
 
             if [[ "$cur" != -* ]]; then
                 set_prefix
-                if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
+                if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
                     get_entries
                     [ -z "$cur" ] && \
                     files=$( command ls -Ad !(CVS) ) || \
@@ -302,7 +302,7 @@ _cvs()
         remove)
             if [[ "$cur" != -* ]]; then
                 set_prefix
-                if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
+                if [[ $cword -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
                     get_entries
                     # find out what files are missing
                     for i in "${entries[@]}"; do
diff --git a/completions/cvsps b/completions/cvsps
index df64db4..f27f2f3 100644
--- a/completions/cvsps
+++ b/completions/cvsps
@@ -4,9 +4,8 @@ have cvsps || return
 
 _cvsps()
 {
-    COMPREPLY=()
-    local cur prev
-    _get_comp_words_by_ref -n : cur prev
+    local cur prev words cword
+    _init_completion -n : || return
 
     case $prev in
         -h|-z|-f|-d|-l|--diff-opts|--debuglvl)

-- 
bash-completion



More information about the Bash-completion-commits mailing list