# apt-reverse.bash -- bash completion for apt-reverse

# Copyright 2006, 2007 Kevin Ryde

# apt-reverse.bash is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# apt-reverse.bash is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You can get a copy of the GNU General Public License online at
# <http://www.gnu.org/licenses>.


# This script sets up command line completions in bash for the apt-reverse
# program.  See "Programmable Completion" and "Commands For Completion" in
# the bash manual for how these completion setups work.
#
# This script can be used standalone, or together with the bash_completion
# project
#
#     http://freshmeat.net/projects/bashcompletion/
#

# To install you can either
#
# 1) Source from your .bashrc,
#
#        . /my-directory/apt-reverse.bash
#
# 2) Or load it with bash_completion, to have it only when using that, either
#
#    2a) Source from your ~/.bash_completion file,
#
#            . /my-directory/apt-reverse.bash
#
#    2b) Or put it in the $BASH_COMPLETION_DIR directory (which might be for
#        instance "/etc/bash_completion.d", and bash_completion will source
#        it from there (along with everything else in that directory).
#

# Revisions:
# Version 1 - the first version.


_apt-reverse()
{
  # $1 is command being completed, ie. "apt-reverse"
  # $2 is current word, ie. the one to complete
  # $3 is the preceding word
  #
  local cur=$2 prev=$3

  # command line option
  case "$cur" in
    -*)
      local options='
    	-a --all
    	-d --descriptions
    	-i --installed
    	--help
    	--version
        --'
      local IFS=$' \n\t'
      COMPREPLY=( $( compgen -W "$options" -- $cur ) )
      return 0
      ;;
    *)
      COMPREPLY=( $(apt-cache pkgnames "$cur" 2>/dev/null) )
      return 0
      ;;
  esac

  return 0
}

complete -F _apt-reverse apt-reverse



# Local variables:
# mode: sh
# sh-shell: bash
# sh-basic-offset: 2
# End:
