updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / aurget / bash_completion
blob911cd5af08c9db544d0a5d48cb8a932d70a558ae
1 #!/bin/bash
3 _aurget() {
4 local cur prev longopts ng_set aurget_exec aurget
6 # save current nullglob setting and turn it on
7 ng_set=$(shopt -p nullglob)
8 shopt -s nullglob
10 COMPREPLY=()
11 cur=${COMP_WORDS[COMP_CWORD]}
12 prev=${COMP_WORDS[COMP_CWORD-1]}
14 # get full executable
15 aurget_exec=$(type -P aurget)
16 [[ -z "$aurget_exec" ]] && return 0
18 # get short executable too
19 aurget=$(basename "$aurget_exec")
22 # valid long options
23 longopts='--devel --deps --nodeps --edit --noedit \
24 --discard --nodiscard --nocolor --noconfirm'
26 # all valid options
27 allopts='-S -Sd -Sb -Sy -Su -Sdu -Sbu -Syu -Ss -Ssq -Sp -Si \
28 --devel --deps --nodeps --edit --noedit --discard \
29 --nodiscard --nocolor --noconfirm --ignore --mopt \
30 --popt --version --help'
32 if [[ $(id -u) -eq 0 ]]; then
33 aurget_exec+=' --asroot'
34 longopts+=' --asroot'
37 case "$prev" in
38 # complete with all opts
39 *$aurget) COMPREPLY=( $(compgen -W "$allopts" -- $cur) ) ;;
41 # don't complete boyond these
42 -h|-v|--@(help|version|ignore|@(m|p)opt)) return 0 ;;
44 # complete with long opts
45 -S*u*|--*) COMPREPLY=( $(compgen -W "$longopts" -- $cur) ) ;;
47 # complete with package search
48 -S*) COMPREPLY=( $(compgen -W "$($aurget_exec -Ssq $cur)" -- $cur ) ) ;;
49 esac
51 # restore the previous nullglob setting
52 $ng_set
55 complete -F _aurget aurget