| 28 | | |
| 29 | | ---- |
| 30 | | |
| 31 | | {{{ |
| 32 | | #!bash |
| 33 | | # Source this file in bash to get command completion (using tab) |
| 34 | | # for boinc and boinccmd |
| 35 | | # Written by Frank S. Thomas |
| 36 | | |
| 37 | | _boinc() |
| 38 | | { |
| 39 | | local cur prev opts |
| 40 | | COMPREPLY=() |
| 41 | | cur="${COMP_WORDS[COMP_CWORD]}" |
| 42 | | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 43 | | |
| 44 | | opts="$(boinc --help | \ |
| 45 | | sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')" |
| 46 | | |
| 47 | | # Handle options that require one or more arguments. |
| 48 | | case "$prev" in |
| 49 | | --attach_project|--detach_project|--reset_project|--update_prefs|\ |
| 50 | | --gui_rpc_port) |
| 51 | | return 0 |
| 52 | | ;; |
| 53 | | esac |
| 54 | | |
| 55 | | # Handle options that require two arguments. |
| 56 | | if [[ COMP_CWORD -gt 1 ]]; then |
| 57 | | pprev="${COMP_WORDS[COMP_CWORD-2]}" |
| 58 | | |
| 59 | | case "$pprev" in |
| 60 | | --attach_project) |
| 61 | | return 0 |
| 62 | | ;; |
| 63 | | esac |
| 64 | | fi |
| 65 | | |
| 66 | | if [[ "$cur" == -* ]]; then |
| 67 | | COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) |
| 68 | | return 0 |
| 69 | | fi |
| 70 | | } |
| 71 | | complete -F _boinc -o default boinc |
| 72 | | |
| 73 | | _boinccmd() |
| 74 | | { |
| 75 | | local cur prev opts cmds |
| 76 | | COMPREPLY=() |
| 77 | | cur="${COMP_WORDS[COMP_CWORD]}" |
| 78 | | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 79 | | |
| 80 | | opts="--host --passwd -h --help -V --version" |
| 81 | | cmds="$(boinccmd --help 2>&1 | \ |
| 82 | | sed -n -r 's/^[[:space:]]*(--[a-z_]*).*/\1/p')" |
| 83 | | |
| 84 | | # The following construct assures that: |
| 85 | | # - no command follows if one of $opts or $cmds was given |
| 86 | | # - after --host follows only one command or --passwd and one command |
| 87 | | # - after --passwd follows only one command |
| 88 | | if [[ $COMP_CWORD -eq 1 ]]; then |
| 89 | | COMPREPLY=( $(compgen -W "$opts $cmds" -- "$cur") ) |
| 90 | | return 0 |
| 91 | | else |
| 92 | | if [[ "${COMP_WORDS[@]}" =~ ".* --host .* --passwd .*" ]]; then |
| 93 | | if [[ $COMP_CWORD -eq 5 ]]; then |
| 94 | | COMPREPLY=( $(compgen -W "$cmds" -- "$cur") ) |
| 95 | | fi |
| 96 | | elif [[ "${COMP_WORDS[@]}" =~ ".* --passwd .*" ]]; then |
| 97 | | if [[ $COMP_CWORD -eq 3 ]]; then |
| 98 | | COMPREPLY=( $(compgen -W "$cmds" -- "$cur") ) |
| 99 | | fi |
| 100 | | elif [[ "${COMP_WORDS[@]}" =~ ".* --host .*" ]]; then |
| 101 | | if [[ $COMP_CWORD -eq 3 ]]; then |
| 102 | | COMPREPLY=( $(compgen -W "--passwd $cmds" -- "$cur") ) |
| 103 | | fi |
| 104 | | fi |
| 105 | | fi |
| 106 | | |
| 107 | | # Handle options/commands that require one or more arguments. |
| 108 | | case "$prev" in |
| 109 | | --get_messages|--passwd) |
| 110 | | return 0 |
| 111 | | ;; |
| 112 | | |
| 113 | | --host) |
| 114 | | _known_hosts |
| 115 | | return 0 |
| 116 | | ;; |
| 117 | | |
| 118 | | --set_run_mode|--set_network_mode) |
| 119 | | COMPREPLY=( $(compgen -W "always auto never" -- "$cur") ) |
| 120 | | return 0 |
| 121 | | ;; |
| 122 | | |
| 123 | | --set_screensaver_mode) |
| 124 | | COMPREPLY=( $(compgen -W "on off" -- "$cur") ) |
| 125 | | return 0 |
| 126 | | ;; |
| 127 | | esac |
| 128 | | } |
| 129 | | complete -F _boinccmd boinccmd |
| 130 | | # vim: syntax=sh |
| 131 | | }}} |