[Bash-completion-commits] [bash-completion] 02/02: Refactor bts and uscan, since they use common functions

David Paleino dapal at debian.org
Tue Nov 26 17:29:49 UTC 2013


This is an automated email from the git hooks/post-receive script.

dapal pushed a commit to branch master
in repository bash-completion.

commit 780d97c5ac41a1d170fa294811e8cadffa550248
Author: David Paleino <dapal at debian.org>
Date:   Tue Nov 26 18:29:34 2013 +0100

    Refactor bts and uscan, since they use common functions
---
 completions/apt-cache | 20 +++++++++++++++++---
 completions/bts       | 25 +++++--------------------
 completions/uscan     | 12 +-----------
 3 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/completions/apt-cache b/completions/apt-cache
index 085a964..48de54f 100644
--- a/completions/apt-cache
+++ b/completions/apt-cache
@@ -1,5 +1,20 @@
 # Debian apt-cache(8) completion                           -*- shell-script -*-
 
+# List APT binary packages
+_apt_cache_packages() {
+    apt-cache --no-generate pkgnames "$cur" 2> /dev/null
+}
+
+# List APT source packages
+_apt_cache_sources() {
+    apt-cache dumpavail | command grep "^Source: $1" | cut -f2 -d" " | sort -u
+}
+
+# List APT source packages
+_apt_cache_src_packages() {
+    compgen -W '$( _apt_cache_sources "$cur" )' -- "$cur"
+}
+
 _apt_cache()
 {
     local cur prev words cword
@@ -23,13 +38,12 @@ _apt_cache()
             ;;
 
         showsrc)
-            COMPREPLY=( $( apt-cache dumpavail | \
-                command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
+            COMPREPLY=( $( _apt_cache_sources "$cur" ) )
             return 0
             ;;
 
         *)
-            COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" 2> /dev/null ) )
+            COMPREPLY=( $( _apt_cache_packages ) )
             return 0
             ;;
 
diff --git a/completions/bts b/completions/bts
index 0e087b4..ef006c0 100644
--- a/completions/bts
+++ b/completions/bts
@@ -6,25 +6,10 @@ _cached_bugs() {
     find $HOME/.devscripts_cache/bts -maxdepth 1 -name "$cur[0-9]*.html" -printf "%f\n" | cut -d'.' -f1
 }
 
-# List APT binary packages
-_packages() {
-    apt-cache --no-generate pkgnames "$cur" 2> /dev/null
-}
-
-# List APT source packages
-_apt_cache_sources() {
-    apt-cache dumpavail | command grep "^Source: $1" | cut -f2 -d" " | sort -u
-}
-
-# List APT source packages
-_src_packages() {
-    compgen -W '$( _apt_cache_sources "$cur" )' -- "$cur"
-}
-
 # List APT source packages prefixed with "src:"
 _src_packages_with_prefix() {
     ppn=${cur:4} # partial package name, after stripping "src:"
-    compgen -P "src:" -W '$( _apt_cache_sources "$ppn" )' -- "$ppn"
+    compgen -P "src:" -W '$( _xfunc apt-cache _apt_cache_sources "$ppn" )' -- "$ppn"
 }
 
 
@@ -70,16 +55,16 @@ _bts()
             return 0
             ;;
         package)
-            COMPREPLY=( $( _packages ) )
+            COMPREPLY=( $( _xfunc apt-cache _apt_cache_packages ) )
             return 0
             ;;
         cache)
-            COMPREPLY=( $( _packages ) $( _src_packages_with_prefix )
+            COMPREPLY=( $( _xfunc apt-cache _apt_cache_packages ) $( _src_packages_with_prefix )
                 $( compgen -W 'from: release-critical RC' -- "$cur" ))
             return 0
             ;;
         cleancache)
-            COMPREPLY=( $( _packages ) $( _src_packages_with_prefix )
+            COMPREPLY=( $( _xfunc apt-cache _apt_cache_packages ) $( _src_packages_with_prefix )
                 $( compgen -W 'from: tag: usertag: ALL' -- "$cur" ))
             return 0
             ;;
@@ -93,7 +78,7 @@ _bts()
             # COMP_WORDS would be: "bts cleancache src : <partial_pkg_name>"
             pos=$((COMP_CWORD - 2))
             if [[ $pos -gt 0 && "${COMP_WORDS[$pos]}" == "src" ]]; then
-                COMPREPLY=( $( _src_packages ) )
+                COMPREPLY=( $( _xfunc apt-cache _apt_cache_src_packages ) )
                 return 0
             fi
             ;;
diff --git a/completions/uscan b/completions/uscan
index f7cb8f3..4d3d2a1 100644
--- a/completions/uscan
+++ b/completions/uscan
@@ -1,15 +1,5 @@
 # uscan completion                                      -*- shell-script -*-
 
-# List APT source packages
-_apt_cache_sources() {
-    apt-cache dumpavail | command grep "^Source: $1" | cut -f2 -d" "
-}
-
-# List APT source packages
-_src_packages() {
-    compgen -W '$( _apt_cache_sources "$cur" )' -- "$cur"
-}
-
 _uscan()
 {
     local cur prev split
@@ -17,7 +7,7 @@ _uscan()
 
     case $prev in
         --package)
-            COMPREPLY=( $( _src_packages ))
+            COMPREPLY=( $( _xfunc apt-cache _apt_cache_src_packages ))
             return 0
             ;;
         --watchfile)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/bash-completion/bash-completion.git



More information about the Bash-completion-commits mailing list