Use python-argcompletion.

This commit is contained in:
Bastian Kleineidam 2013-02-27 20:55:24 +01:00
parent dcf75a08e7
commit 13eddd752e
2 changed files with 16 additions and 36 deletions

5
patool
View File

@ -141,6 +141,11 @@ def create_argparser():
parser_search.add_argument('archive', help='the archive file') parser_search.add_argument('archive', help='the archive file')
# formats # formats
subparsers.add_parser('formats', help="show supported archive formats") subparsers.add_parser('formats', help="show supported archive formats")
try:
import argcomplete
argcomplete.autocomplete(parser)
except ImportError:
pass
return parser return parser

View File

@ -1,44 +1,19 @@
# patool completion # patool completion
#
have patool && have patool &&
{
_patool() _patool()
{ {
local cur prev commands options command local cur prev
COMPREPLY=() COMPREPLY=()
cur=`_get_cword` cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
commands='extract list test create diff repack formats' if type _argcomplete &> /dev/null; then
_argcomplete "$@"
if [[ $COMP_CWORD -eq 1 ]] ; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help' -- $cur ) )
else
COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
fi
else
command=${COMP_WORDS[1]}
if [[ "$cur" == -* ]]; then
# possible options for the command
options=''
case $command in
extract|list|test|create)
options='--verbose'
;;
esac
options="$options --help"
COMPREPLY=( $( compgen -W "$options" -- $cur ) )
else else
_filedir _filedir
fi fi
fi
return 0 return 0
} }
complete -F _patool $filenames patool complete -F _patool $filenames patool
}