[Buildd-tools-devel] Bug#519745: Bug#519745: schroot: Add bash completion script

Roger Leigh rleigh at codelibre.net
Sat Mar 21 15:44:44 UTC 2009


On Sat, Mar 21, 2009 at 10:55:13AM -0400, Tim Abbott wrote:
> On Sat, 21 Mar 2009, Roger Leigh wrote:
> 
> > On Sat, Mar 14, 2009 at 03:41:03PM -0400, Tim Abbott wrote:
> > 
> > > I wrote a bash_completion script for schroot (attached); it completes on 
> > > both option names and chroot names (after the -c argument).
> > 
> > Many thanks!  I'll be happy to include this.  While it has a
> > copyright statement, it doesn't have any licence attached,
> > which precludes distribution.  If you are happy for this to
> > be distributed under the GPLv3+, please could you include the
> > appropriate GPL boilerplate text?
> 
> Yeah, sure.  I think I left this off because I felt silly posting a file 
> that's more than 1/2 copyright notice, but you're probably right that I 
> should include it.  New file with boilerplate attached.

Thanks!

> By the way, it currently is the case that when new options are added to 
> schroot, they need to be added to the list of options in the completion 
> script for them to complete; I just wanted to make sure you were aware of 
> this.

OK.  It's exactly the same for zsh completions as well.

BTW, you can always get a complete list of options from
  schroot --help | grep '[[:space:]]*-'
which might make it more flexible.  The --help output is dynamically
generated, so is always comprehensive.  A little sed/echo trickery will
get you a space separated list of options.

Also, if you wanted to be *really* clever, and if bash allows this,
you could also complete the usernames and session names in addition
to the chroot names.  Does this work for just -c or --chroot as well?
The existing zsh completions (attached) do just this!


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
-------------- next part --------------
#compdef schroot

local expl context state line
typeset -A opt_args

_arguments -S \
       '(-h --help)'{-h,--help}'[help]' \
       '(-a --all)'{-a,--all}'[select all chroots and active sessions]' \
       '--all-chroots[select all chroots]' \
       '--all-sessions[select all active sessions]' \
       '*'{-c,--chroot=}'[use specified chroot]:chroot:->chroot' \
       '(-d --directory)'{-d,--directory=}'[directory to use]:dir:_files -W / -P /' \
       '(-u --user)'{-u,--user=}'[username (default current user)]:user:_users' \
       '(-l --list)'{-l,--list}'[list available chroots]' \
       '(-i --info)'{-i,--info}'[show information about selected chroots]' \
       '--location[print location of selected chroots]' \
       '--config[dump configuration of selected chroots]' \
       '(-p --preserve-environment)'{-p,--preserve-environment}'[preserve user environment]' \
       '(-q --quiet)'{-q,--quiet}'[quiet]' \
       '(-v --verbose)'{-v,--verbose}'[verbose]' \
       '(-V --version)'{-V,--version}'[version]' \
       '(-b --begin-session)'{-b,--begin-session}'[begin a session; returns a session ID]' \
       '--recover-session[recover an existing session]' \
       '(-e --end-session)'{-e,--end-session}'[end an existing session]' \
       '(-f --force)'{-f,--force}'[force operation]' \
       '(-):command name: _command_names -e' \
       '*::arguments: _normal' && return 0

case "$state" in
	(chroot)
	_wanted tag expl 'chroot' \
	  compadd $(schroot -l -a)
	;;
esac


More information about the Buildd-tools-devel mailing list