Merge pull request #963 from AladW/view-options
[aurutils.git] / completions / bash / aurutils.in
blob445a02f2a3f499d1a2b00be6116b967cdf22b210
1 #!/bin/bash
3 cat <<'EOF'
4 _aur_completion()
6 local cur prev words cword
7 _get_comp_words_by_ref cur prev words cword
9 declare -A default_cmds
11 EOF
12 source ./command_opts.sh
13 default_opts
14 cat <<'EOF'
16 # complete subcommands
17 if [[ $cword -eq 1 ]]; then
18 COMPREPLY=( $(compgen -W "${!default_cmds[*]}" -- "$cur") )
19 return
22 # If there's an override for subcommand, use it
23 if declare -F "_aurutils_${words[1]/-/_/}" >/dev/null ; then
24 "_aurutils_${words[1]}"
25 return
28 # Complete with the generated opts stored above, unless the previous option
29 # is stored with an : suffix, because the option requires an argument.
30 # Fallback to default (files) completion in such cases.
32 _fallback_completion
35 _fallback_completion(){
36 opts=(${default_cmds[${words[1]}]})
37 if [[ ${opts[*]} != *$prev:* ]] || [[ $cword -eq 2 ]]; then
38 COMPREPLY=($(compgen -W "${opts[*]%:}" -- "$cur"));
42 _complete_with_repos() {
43 opts=($(aur repo --repo-list))
44 COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
47 _aurutils_build() {
48 case $prev in
49 -d|--database|--repo)
50 _complete_with_repos ;;
51 *) _fallback_completion ;;
52 esac
55 _aurutils_repo() {
56 case $prev in
57 -d|--database|--repo)
58 _complete_with_repos ;;
59 *) _fallback_completion ;;
60 esac
63 _aurutils_repo_filter() {
64 case $prev in
65 -d|--database|--repo)
66 _complete_with_repos ;;
67 *) _fallback_completion ;;
68 esac
71 _aurutils_sync() {
72 case $prev in
73 -d|--database|--repo)
74 _complete_with_repos ;;
75 *) _fallback_completion ;;
76 esac
79 complete -o bashdefault -o default -o nosort -F _aur_completion aur
80 EOF