BASH completion for boinc_cmd

Frank S. Thomas frank at
Fri Jun 22 09:13:58 UTC 2007

Hello all,

The BASH shell has the neat facility that it can complete commands when you 
press [TAB]. For boinc_cmd I've written a small script (which is attached) 
which goes a bit further and can complete boinc_cmds own commands and 
options. For example if you type boinc_cmd --get[TAB] it gives you all 
commands which begin with --get:
--get_cc_status            --get_project_status
--get_disk_usage           --get_proxy_settings
--get_file_transfers       --get_results
--get_host_info            --get_screensaver_mode
--get_messages             --get_simple_gui_info
--get_project_config       --get_state
If you now press 'p' the selection is reduced to:
--get_project_config       --get_project_status
--get_project_config_poll  --get_proxy_settings
and so on. The script also completes host names after the --host option.

I will distribute this script within the Debian package of the BOINC client 
(there it is /etc/bash_completion.d/boinc_cmd), but I think it could be 
interesting for a broader audience and therefore posting here on boinc_dev to 
ask if it should be included in your Subversion repository. To test it just 
download the file and source it: . ./boinc_cmd and then type and let it 
complete boinc_cmd's commands.

Comments are welcome.


BTW: the latest version of this file is always at:
-------------- next part --------------
    local cur prev opts cmds

    opts="--host --passwd -h --help -V --version"
    cmds="$(boinc_cmd --help 2>&1 | sed -r 's/^[[:space:]](--[a-z_]*).*/\1/' \
        | grep '^--')"

    # The following if construct assures that:
    # - no command follows if one of $opts or $cmds was given
    # - after --host follows only one command or --passwd and one command
    # - after --passwd follows only one command
    if [[ $COMP_CWORD -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "$opts $cmds" -- "$cur") )
        return 0
    elif [[ "${COMP_WORDS[@]}" =~ ".* --passwd .*" ]]; then
        if [[ "$prev" == --passwd ]]; then
            return 0
        elif [[ $COMP_CWORD -lt 6 ]]; then
            COMPREPLY=( $(compgen -W "$cmds" -- "$cur") )
            return 0
    elif [[ "${COMP_WORDS[@]}" =~ ".* --host .*" ]]; then
        if [[ "$prev" == --host ]]; then
        elif [[ $COMP_CWORD -lt 4 ]]; then
            COMPREPLY=( $(compgen -W "--passwd $cmds" -- "$cur") )
            return 0
complete -F _boinc_cmd boinc_cmd
# vim: syntax=sh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : 

More information about the pkg-boinc-devel mailing list