| | 1 | {{{ |
| | 2 | # Source this file in bash to get command completion (using tab) |
| | 3 | # for boinc_client and boinc_cmd |
| | 4 | # Written by Frank S. Thomas |
| | 5 | |
| | 6 | _boinc_client() |
| | 7 | { |
| | 8 | local cur prev opts |
| | 9 | COMPREPLY=() |
| | 10 | cur="${COMP_WORDS[COMP_CWORD]}" |
| | 11 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| | 12 | |
| | 13 | opts="$(boinc_client --help | \ |
| | 14 | sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')" |
| | 15 | |
| | 16 | # Handle options that require one or more arguments. |
| | 17 | case "$prev" in |
| | 18 | --attach_project|--detach_project|--reset_project|--update_prefs|\ |
| | 19 | --gui_rpc_port) |
| | 20 | return 0 |
| | 21 | ;; |
| | 22 | esac |
| | 23 | |
| | 24 | # Handle options that require two arguments. |
| | 25 | if [[ COMP_CWORD -gt 1 ]]; then |
| | 26 | pprev="${COMP_WORDS[COMP_CWORD-2]}" |
| | 27 | |
| | 28 | case "$pprev" in |
| | 29 | --attach_project) |
| | 30 | return 0 |
| | 31 | ;; |
| | 32 | esac |
| | 33 | fi |
| | 34 | |
| | 35 | if [[ "$cur" == -* ]]; then |
| | 36 | COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) |
| | 37 | return 0 |
| | 38 | fi |
| | 39 | } |
| | 40 | complete -F _boinc_client -o default boinc_client |
| | 41 | |
| | 42 | _boinc_cmd() |
| | 43 | { |
| | 44 | local cur prev opts cmds |
| | 45 | COMPREPLY=() |
| | 46 | cur="${COMP_WORDS[COMP_CWORD]}" |
| | 47 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| | 48 | |
| | 49 | opts="--host --passwd -h --help -V --version" |
| | 50 | cmds="$(boinc_cmd --help 2>&1 | \ |
| | 51 | sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')" |
| | 52 | |
| | 53 | # The following construct assures that: |
| | 54 | # - no command follows if one of $opts or $cmds was given |
| | 55 | # - after --host follows only one command or --passwd and one command |
| | 56 | # - after --passwd follows only one command |
| | 57 | if [[ $COMP_CWORD -eq 1 ]]; then |
| | 58 | COMPREPLY=( $(compgen -W "$opts $cmds" -- "$cur") ) |
| | 59 | return 0 |
| | 60 | else |
| | 61 | if [[ "${COMP_WORDS[@]}" =~ ".* --host .* --passwd .*" ]]; then |
| | 62 | if [[ $COMP_CWORD -eq 5 ]]; then |
| | 63 | COMPREPLY=( $(compgen -W "$cmds" -- "$cur") ) |
| | 64 | fi |
| | 65 | elif [[ "${COMP_WORDS[@]}" =~ ".* --passwd .*" ]]; then |
| | 66 | if [[ $COMP_CWORD -eq 3 ]]; then |
| | 67 | COMPREPLY=( $(compgen -W "$cmds" -- "$cur") ) |
| | 68 | fi |
| | 69 | elif [[ "${COMP_WORDS[@]}" =~ ".* --host .*" ]]; then |
| | 70 | if [[ $COMP_CWORD -eq 3 ]]; then |
| | 71 | COMPREPLY=( $(compgen -W "--passwd $cmds" -- "$cur") ) |
| | 72 | fi |
| | 73 | fi |
| | 74 | fi |
| | 75 | |
| | 76 | # Handle options/commands that require one or more arguments. |
| | 77 | case "$prev" in |
| | 78 | --get_messages|--passwd) |
| | 79 | return 0 |
| | 80 | ;; |
| | 81 | |
| | 82 | --host) |
| | 83 | _known_hosts |
| | 84 | return 0 |
| | 85 | ;; |
| | 86 | |
| | 87 | --set_run_mode|--set_network_mode) |
| | 88 | COMPREPLY=( $(compgen -W "always auto never" -- "$cur") ) |
| | 89 | return 0 |
| | 90 | ;; |
| | 91 | |
| | 92 | --set_screensaver_mode) |
| | 93 | COMPREPLY=( $(compgen -W "on off" -- "$cur") ) |
| | 94 | return 0 |
| | 95 | ;; |
| | 96 | esac |
| | 97 | } |
| | 98 | complete -F _boinc_cmd boinc_cmd |
| | 99 | # vim: syntax=sh |
| | 100 | }}} |