Use python-argcompletion.
This commit is contained in:
parent
dcf75a08e7
commit
13eddd752e
5
patool
5
patool
|
@ -141,6 +141,11 @@ def create_argparser():
|
|||
parser_search.add_argument('archive', help='the archive file')
|
||||
# formats
|
||||
subparsers.add_parser('formats', help="show supported archive formats")
|
||||
try:
|
||||
import argcomplete
|
||||
argcomplete.autocomplete(parser)
|
||||
except ImportError:
|
||||
pass
|
||||
return parser
|
||||
|
||||
|
||||
|
|
|
@ -1,44 +1,19 @@
|
|||
# patool completion
|
||||
#
|
||||
|
||||
have patool &&
|
||||
{
|
||||
_patool()
|
||||
{
|
||||
local cur prev commands options command
|
||||
local cur prev
|
||||
|
||||
COMPREPLY=()
|
||||
cur=`_get_cword`
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
commands='extract list test create diff repack formats'
|
||||
|
||||
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
|
||||
_filedir
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
if type _argcomplete &> /dev/null; then
|
||||
_argcomplete "$@"
|
||||
else
|
||||
_filedir
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
complete -F _patool $filenames patool
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue