Bug#660838: pbuilder: Add complete bash_autocompletion for all flags and arguments

Maarten Bezemer maarten.bezemer at gmail.com
Wed Feb 22 09:09:28 UTC 2012


Package: pbuilder
Version: 0.206
Severity: normal
Tags: patch

Currently, pbuidler only supports bash_completion for the commands (first argument) and filename completion for the .dsc file.

This patch adds additional support for all flags and filename/directory completion for flags that require this.

The patch is submitted (and accepted) to Ubuntu in two phases, see these bug reports:
- https://bugs.launchpad.net/ubuntu/+source/pbuilder/+bug/770529
- https://bugs.launchpad.net/ubuntu/+source/pbuilder/+bug/933339

Please consider to apply this patch.
Thanks in advance,
  Maarten

*** bash_completion.debdiff
--- pbuilder-0.206/bash_completion.d/pbuilder	2010-01-31 04:52:57.000000000 +0100
+++ pbuilder-0.207/bash_completion.d/pbuilder	2012-02-22 10:07:01.000000000 +0100
@@ -7,21 +7,73 @@
 # adapted to pbuilder, the license is GPLv2 or later.
 # Copyright 2007 Junichi Uekawa <dancer at debian.org>
 
-have pbuilder &&
+have pbuilder && {
 _pbuilder()
 {
-    local cur options
+    local cur prev command i
 
     COMPREPLY=()
-    cur=${COMP_WORDS[COMP_CWORD]}
-    options='--create --update --build --login --execute --dumpconfig'
+    _get_comp_words_by_ref cur prev
 
-    if [ $COMP_CWORD -eq 1 ]; then
-        COMPREPLY=( $( compgen -W "$options" | grep "^$cur" ) )
-    elif [ "${COMP_WORDS[1]}" = --build ]; then
-        COMPREPLY=( $( compgen -o filenames -G "$cur*.dsc" ) )
+
+    if [[ $COMP_CWORD -eq 1 ]]; then
+        COMPREPLY=( $( compgen -W '--create --update --build --login --execute \
+            --dumpconfig create update build login execute dumpconfig' -- "$cur" ) )
+        return 0
+    fi
+
+    _expand || return 0
+
+    # find the last option flag
+    if [[ $cur != -* ]]; then
+        i=$COMP_CWORD
+        while [[ $prev != -* && $i != 2 ]]; do
+            i=$((i-1))
+            prev=${COMP_WORDS[i-1]}
+        done
     fi
 
+    command=${COMP_WORDS[1]}
+
+    case $prev in
+        --basetgz)
+            # tgz file completion
+            _filedir 'tgz'
+            return 0
+            ;;
+        --configfile|--logfile)
+            # Any file
+            _filedir
+            return 0
+            ;;
+        --buildplace|--buildresults)
+            # Any directory
+            _filedir -d
+            return 0
+            ;;
+        *)
+            # Provide available flags
+            COMPREPLY=( $( compgen -W '--basetgz --buildplace --mirror --othermirror \
+                --http-proxy --distribution --architecture --components --buildresult \
+                --aptcache --removepackages --extrapackages --configfile --hookdir \
+                --debemail --debbuildopts --logfile --pkgname-logfile --aptconfdir \
+                --timeout --override-config  --binary-arch --preserve-buildplace \
+                --bindmounts --debug --twice --autocleanaptcache --compressprog \
+                --debootstrapopts --save-after-login --save-after-exec --debootstrap' \
+                -- "$cur" ) )
+            if [[ $prev = @(--aptcache|--hookdir) ]]; then
+                # Optionally provide a directory
+                _filedir -d
+            fi
+            if [[ $cur != -* && $command == @(--build|build) ]]; then
+                # dsc file completion
+                _filedir "dsc"
+            fi
+            return 0
+            ;;
+    esac
+
     return 0
 }
-[ "$have" ] && complete -F _pbuilder -o filenames pbuilder
+complete -F _pbuilder pbuilder
+}
--- pbuilder-0.206/debian/changelog	2012-01-28 06:58:59.000000000 +0100
+++ pbuilder-0.207/debian/changelog	2012-02-22 09:49:20.000000000 +0100
@@ -1,3 +1,9 @@
+pbuilder (0.207) UNRELEASED; urgency=low
+
+  * Auto complete flags and required file/directory names
+
+ -- Maarten Bezemer <maarten.bezemer at gmail.com>  Wed, 22 Feb 2012 09:42:23 +0100
+
 pbuilder (0.206) unstable; urgency=low
 
   [ Matthew Palmer ]


-- System Information:
Debian Release: wheezy/sid
  APT prefers oneiric-security
  APT policy: (990, 'oneiric-security'), (900, 'oneiric-updates'), (500, 'oneiric'), (400, 'oneiric-proposed'), (100, 'oneiric-backports'), (90, 'precise')
Architecture: amd64 (x86_64)

Kernel: Linux 3.0.0-16-generic (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages pbuilder depends on:
ii  coreutils                8.5-1ubuntu6    GNU core utilities
ii  debconf [debconf-2.0]    1.5.40ubuntu1   Debian configuration management sy
ii  debianutils              4.0.2           Miscellaneous utilities specific t
ii  debootstrap              1.0.37          Bootstrap a basic Debian system
ii  wget                     1.12-3.1ubuntu1 retrieves files from the web

Versions of packages pbuilder recommends:
ii  devscripts              2.11.1ubuntu3.1  scripts to make the life of a Debi
ii  fakeroot                1.17-1           tool for simulating superuser priv
ii  sudo                    1.7.4p6-1ubuntu2 Provide limited super user privile

Versions of packages pbuilder suggests:
pn  cowdancer                     <none>     (no description available)
pn  gdebi-core                    <none>     (no description available)
pn  pbuilder-uml                  <none>     (no description available)

-- debconf information excluded





More information about the Pbuilder-maint mailing list