updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / boinc-svn / boinc.bash
blob34daa3b9762c08178b04a5f7197b852cad42faae
1 # Source this file in BASH to get command completion (using tab) for
2 # boinc and boinccmd. Written by Frank S. Thomas <fst@debian.org>.
3 # See also: http://boinc.berkeley.edu/trac/wiki/BashCommandCompletion
5 _boinc()
7 local cur prev opts
8 COMPREPLY=()
9 cur="${COMP_WORDS[COMP_CWORD]}"
10 prev="${COMP_WORDS[COMP_CWORD-1]}"
12 opts="$(boinc_client --help | \
13 sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')"
15 # Handle options that require one or more arguments.
16 case "$prev" in
17 --attach_project|--detach_project|--reset_project|--update_prefs|\
18 --gui_rpc_port)
19 return 0
21 esac
23 # Handle options that require two arguments.
24 if [[ COMP_CWORD -gt 1 ]]; then
25 pprev="${COMP_WORDS[COMP_CWORD-2]}"
27 case "$pprev" in
28 --attach_project)
29 return 0
31 esac
34 if [[ "$cur" == -* ]]; then
35 COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
36 return 0
39 complete -F _boinc -o default boinc_client
41 _boinccmd()
43 local cur prev opts cmds
44 COMPREPLY=()
45 cur="${COMP_WORDS[COMP_CWORD]}"
46 prev="${COMP_WORDS[COMP_CWORD-1]}"
48 opts="--host --passwd -h --help -V --version"
49 cmds="$(boinc_cmd --help 2>&1 | \
50 sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')"
52 # The following construct assures that:
53 # - no command follows if one of $opts or $cmds was given
54 # - after --host follows only one command or --passwd and one command
55 # - after --passwd follows only one command
56 if [[ $COMP_CWORD -eq 1 ]]; then
57 COMPREPLY=( $(compgen -W "$opts $cmds" -- "$cur") )
58 return 0
59 else
60 if [[ "${COMP_WORDS[@]}" =~ ".* --host .* --passwd .*" ]]; then
61 if [[ $COMP_CWORD -eq 5 ]]; then
62 COMPREPLY=( $(compgen -W "$cmds" -- "$cur") )
64 elif [[ "${COMP_WORDS[@]}" =~ ".* --passwd .*" ]]; then
65 if [[ $COMP_CWORD -eq 3 ]]; then
66 COMPREPLY=( $(compgen -W "$cmds" -- "$cur") )
68 elif [[ "${COMP_WORDS[@]}" =~ ".* --host .*" ]]; then
69 if [[ $COMP_CWORD -eq 3 ]]; then
70 COMPREPLY=( $(compgen -W "--passwd $cmds" -- "$cur") )
75 # Handle options/commands that require one or more arguments.
76 case "$prev" in
77 --get_messages|--passwd)
78 return 0
81 --host)
82 _known_hosts
83 return 0
86 --set_run_mode|--set_network_mode)
87 COMPREPLY=( $(compgen -W "always auto never" -- "$cur") )
88 return 0
91 --set_screensaver_mode)
92 COMPREPLY=( $(compgen -W "on off" -- "$cur") )
93 return 0
95 esac
97 complete -F _boinccmd boinc_cmd
99 # vim: syntax=sh