you-get/contrib/completion/you-get-completion.bash
Zhiming Wang 3b4a576e6c
Add shell completion definitions for Bash, Fish and Zsh
Paths of completion definitions in this repo are inconsequential, and I
don't know a convention for that, so I just modelled it on git.git
https://github.com/git/git/tree/master/contrib/completion. What's
different here is that instead of using a uniform naming scheme for each
file (you-get-completion.<shellname>), I'm using the conventional name
for each shell, which means _you-get for Zsh, for instance. Users of
each shell should be able to pick out the completion definition for
their shell based on the filenames; in the worst case, they can still
tell from the comment at the top of each file.

Note that I'm no expert on Bash or Fish completion, so
you-get-completion.bash and you-get.fish may not be written in the
idiomatic way. (you-get-completion.bash is most certainly not idiomatic,
if there's an idiom at all.)

Closes #1178.
2016-05-28 18:50:50 -07:00

32 lines
916 B
Bash
Executable File

# Bash completion definition for you-get.
_you-get () {
COMPREPLY=()
local IFS=$' \n'
local cur=$2 prev=$3
local -a opts_without_arg opts_with_arg
opts_without_arg=(
-V --version -h --help -i --info -u --url --json -n --no-merge
--no-caption -f --force --no-proxy -d --debug
)
opts_with_arg=(
-F --format -O --output-filename -o --output-dir -p --player
-c --cookies -x --http-proxy -y --extractor-proxy -t --timeout
)
# Do not complete non option names
[[ $cur == -* ]] || return 1
# Do not complete when the previous arg is an option expecting an argument
for opt in "${opts_with_arg[@]}"; do
[[ $opt == $prev ]] && return 1
done
# Complete option names
COMPREPLY=( $(compgen -W "${opts_without_arg[*]} ${opts_with_arg[*]}" \
-- "$cur") )
return 0
}
complete -F _you-get you-get