[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-11-g344076f

Ville Skyttä ville.skytta at iki.fi
Thu Feb 10 21:55:30 UTC 2011


The following commit has been merged in the master branch:
commit 6042cbe2f524a2956b0490c631339206149870de
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Thu Feb 10 23:51:26 2011 +0200

    Split rpm and rpmbuild completions and improve them both.
    
    The option sets are different, and rpm should not have been used to
    build packages since rpm 4.0, and could not have been used for that
    since rpm 4.1.

diff --git a/CHANGES b/CHANGES
index a8e4299..40a8028 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,7 @@ bash-completion (2.x)
   * Improve gendiff completion.
   * Try harder to find the correct perl executable to run the perl helper with.
   * Drop rpm query support for rpm < 4.1.
+  * Split rpm and rpmbuild completions and improve them both.
 
  -- David Paleino <d.paleino at gmail.com>  Sun, 06 Feb 2011 21:46:37 +0100
 
diff --git a/completions/rpm b/completions/rpm
index 2e32313..b3ff291 100644
--- a/completions/rpm
+++ b/completions/rpm
@@ -15,7 +15,7 @@ _rpm_installed_packages()
         # SUSE's rpmqpack is faster than rpm -qa
         COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )
     else
-        COMPREPLY=( $( rpm -qa --nodigest --nosignature \
+        COMPREPLY=( $( ${1:-rpm} -qa --nodigest --nosignature \
             --queryformat='%{NAME} ' "$cur*" 2>/dev/null ) )
     fi
 }
@@ -23,10 +23,18 @@ _rpm_installed_packages()
 _rpm_groups()
 {
     local IFS=$'\n'
-    COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest --nosignature \
+    COMPREPLY=( $( compgen -W "$( ${1:-rpm} -qa --nodigest --nosignature \
         --queryformat='%{GROUP}\n' 2>/dev/null )" -- "$cur" ) )
 }
 
+_rpm_macros()
+{
+    # get a list of macros
+    COMPREPLY=( $( compgen -W "$( ${1:-rpm} --showrc | sed -ne \
+        's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
+        -- "$cur" ) )
+}
+
 # rpm(8) completion
 #
 _rpm()
@@ -39,24 +47,15 @@ _rpm()
     if [ $COMP_CWORD -eq 1 ]; then
         # first parameter on line
         case $cur in
-            -b*)
-                COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs' \
-                    -- "$cur" ) )
-                ;;
-            -t*)
-                COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts' \
-                    -- "$cur" ) )
-                ;;
             --*)
                 COMPREPLY=( $( compgen -W '--help --version --initdb \
-                    --checksig --recompile --rebuild --resign --addsign \
-                    --rebuilddb --showrc --setperms --setugids --tarbuild \
-                    --eval --install --upgrade --query --freshen --erase \
-                    --verify --querytags --rmsource --rmspec --clean \
-                    --import' -- "$cur" ) )
+                    --checksig --resign --addsign --rebuilddb --showrc \
+                    --setperms --setugids --eval --install --upgrade --query \
+                    --freshen --erase --verify --querytags --import' \
+                    -- "$cur" ) )
                 ;;
             *)
-                COMPREPLY=( $( compgen -W '-b -e -E -F -i -q -t -U -V' \
+                COMPREPLY=( $( compgen -W '-e -E -F -i -q -t -U -V' \
                     -- "$cur" ) )
                 ;;
         esac
@@ -70,10 +69,7 @@ _rpm()
             return 0
             ;;
         --eval|-E)
-            # get a list of macros
-            COMPREPLY=( $( compgen -W "$( rpm --showrc | sed -ne \
-                's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
-                -- "$cur" ) )
+            _rpm_macros $1
             return 0
             ;;
         --pipe)
@@ -96,9 +92,9 @@ _rpm()
             else
                 # complete on capabilities
                 local IFS=$'\n'
-                COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest \
-                    --nosignature --queryformat='%{PROVIDENAME}\n' \
-                    2>/dev/null )" -- "$cur" ) )
+                COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
+                    --queryformat='%{PROVIDENAME}\n' 2>/dev/null )" \
+                    -- "$cur" ) )
             fi
             return 0
             ;;
@@ -108,18 +104,12 @@ _rpm()
             else
                 # complete on capabilities
                 local IFS=$'\n'
-                COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest \
-                    --nosignature --queryformat='%{REQUIRENAME}\n' \
-                    2>/dev/null )" -- "$cur" ) )
+                COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
+                    --queryformat='%{REQUIRENAME}\n' 2>/dev/null )" \
+                    -- "$cur" ) )
             fi
             return 0
             ;;
-        --target)
-            COMPREPLY=( $( compgen -W "$( command rpm --showrc | sed -ne \
-                's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
-                -- "$cur" ) )
-            return 0
-            ;;
         --define|-D|--fileid|--hdrid|--pkgid)
             # argument required but no completions available
             return 0
@@ -151,7 +141,7 @@ _rpm()
                 --noscripts --notriggers --nodeps --test --repackage" \
                 -- "$cur" ) )
             else
-                _rpm_installed_packages
+                _rpm_installed_packages $1
             fi
             ;;
         -q*|--query)
@@ -172,7 +162,7 @@ _rpm()
                 fi
             elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
                 # -qg completion
-                _rpm_groups
+                _rpm_groups $1
             elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
                 # -qp; uninstalled package completion
                 if [[ "$cur" == -* ]]; then
@@ -190,7 +180,7 @@ _rpm()
                         --triggeredby --whatprovides --whatrequires" \
                             -- "$cur" ) )
                 elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then
-                    _rpm_installed_packages
+                    _rpm_installed_packages $1
                 fi
             fi
             ;;
@@ -212,48 +202,18 @@ _rpm()
             elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
                 _filedir
             elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
-                _rpm_groups
+                _rpm_groups $1
             elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
                 _filedir '[rs]pm'
             else
-                _rpm_installed_packages
+                _rpm_installed_packages $1
             fi
             ;;
-        -[bt]*)
-            if [[ "$cur" == -* ]]; then
-                COMPREPLY=( $( compgen -W "$opts --short-circuit --timecheck \
-                    --clean --rmsource --rmspec --test --sign --buildroot \
-                    --target --nobuild --nodeps --nodirtokens" -- "$cur" ) )
-            elif [[ ${COMP_WORDS[1]} == -b* ]]; then
-                _filedir spec
-            else
-                _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
-            fi
-            ;;
-        --rebuild|--recompile)
-            if [[ "$cur" == -* ]]; then
-                COMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \
-                  --rmspec --sign --nodirtokens --target" -- "$cur" ) )
-            else
-                _filedir '@(?(no)src.r|s)pm'
-            fi
-            ;;
-        --tarbuild)
-            _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
-            ;;
         --resign|--addsign)
             _filedir '[rs]pm'
             ;;
         --setperms|--setgids)
-            _rpm_installed_packages
-            ;;
-        --clean|--rmsource|--rmspec)
-            if [[ "$cur" == -* ]]; then
-                COMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \
-                    -- "$cur" ) )
-            else
-                _filedir spec
-            fi
+            _rpm_installed_packages $1
             ;;
         --import|--dbpath|--root)
             if [[ "$cur" == -* ]]; then
@@ -266,8 +226,72 @@ _rpm()
     esac
 
     return 0
-}
-complete -F _rpm rpm rpmbuild
+} &&
+complete -F _rpm rpm
+
+_rpmbuild()
+{
+    COMPREPLY=()
+    local cur prev words split=false
+    _get_comp_words_by_ref cur prev words
+
+    _split_longopt && split=true
+
+    local rpm="${1%build*}"
+    [[ $rpm == $1 ]] || ! type $rpm &>/dev/null && rpm=
+
+    case $prev in
+        --buildroot|--root|-r|--dbpath)
+            _filedir -d
+            return 0
+            ;;
+        --target)
+            COMPREPLY=( $( compgen -W "$( $rpm --showrc | sed -ne \
+                's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
+                -- "$cur" ) )
+            return 0
+            ;;
+        --eval|-E)
+            _rpm_macros $rpm
+            return 0
+            ;;
+        --macros|--rcfile)
+            _filedir
+            return 0
+            ;;
+        --define|-D|--with|--without|--buildpolicy)
+            return 0
+            ;;
+    esac
+
+    $split && return 0
+
+    if [[ $cur == -* ]]; then
+        COMPREPLY=( $( compgen -W "$( _parse_help "$1" )" -- "$cur" ) )
+        return 0
+    fi
+
+    # Figure out file extensions to complete
+    local word ext
+    for word in ${words[@]}; do
+        case $word in
+            -b?)
+                ext=spec
+                break
+                ;;
+            -t?|--tarbuild)
+                ext='@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
+                break
+                ;;
+            --rebuild|--recompile)
+                ext='@(?(no)src.r|s)pm'
+                break
+                ;;
+        esac
+    done
+    [[ -n $ext ]] && _filedir $ext
+} &&
+complete -F _rpmbuild rpmbuild rpmbuild-md5
 }
 
 have gendiff &&
diff --git a/test/completion/rpmbuild.exp b/test/completion/rpmbuild.exp
new file mode 100644
index 0000000..f829b58
--- /dev/null
+++ b/test/completion/rpmbuild.exp
@@ -0,0 +1 @@
+assert_source_completions rpmbuild
diff --git a/test/lib/completions/a2ps.exp b/test/lib/completions/rpmbuild.exp
similarity index 78%
copy from test/lib/completions/a2ps.exp
copy to test/lib/completions/rpmbuild.exp
index 77cd07f..4058d72 100644
--- a/test/lib/completions/a2ps.exp
+++ b/test/lib/completions/rpmbuild.exp
@@ -11,7 +11,7 @@ proc teardown {} {
 setup
 
 
-assert_complete_any "a2ps "
+assert_complete_any "rpmbuild -"
 
 
 sync_after_int

-- 
bash-completion



More information about the Bash-completion-commits mailing list