# 
# bash_completion file for Pd-l2ork. 
# 
# Save as: /etc/bash_completion.d/pd-l2ork or ~/.bash_completion and enjoy never
# having to type any full command line option anymore. Instead you can press
# <TAB>.
#
# If you want to help, these are fine introductions to bash's completion
# feature:
# 
# http://www.debian-administration.org/articles/316
# http://www.debian-administration.org/articles/317
#
# First version written by Frank Barknecht <fbar AT footils.org> Dec 26 2005
# Modified by Ivica Ico Bukvic <ico AT vt.edu> Aug 31 2014 to make it work for pd-l2ork

have pd-l2ork && 
_pd-l2ork() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    # Pd-l2ork's options:
    opts="-help \
    -r \
    -audioindev \
    -audiooutdev \
    -audiodev \
    -inchannels \
    -outchannels \
    -channels \
    -audiobuf \
    -blocksize \
    -sleepgrain \
    -nodac \
    -noadc \
    -noaudio \
    -listdev \
    -oss \
    -32bit \
    -alsa \
    -alsaadd \
    -jack \
    -midiindev \
    -midioutdev \
    -mididev \
    -nomidiin \
    -nomidiout \
    -nomidi \
    -alsamidi \
    -path \
    -nostdpath \
    -stdpath \
    -helppath \
    -open \
    -lib \
    -font-size \
    -font-face \
    -font-weight \
    -verbose \
    -version \
    -d \
    -noloadbang \
    -stderr \
    -nogui \
    -guiport \
    -guicmd \
    -send \
    -noprefs \
    -rt \
    -realtime \
    -nrt \
    -nosleep \
    -schedlib \
    -extraflags \
    -batch \
    -autopatch \
    -k12 \
    -unique"



    # options that require an argument:
    case "${prev}" in
        # directory argument:
        # TODO: colon-separated paths as in "/usr/lib/pd-l2ork/extra:/home/user/pd-l2ork"
        -path)
            COMPREPLY=( $(compgen -d ${cur}) )
            return 0
            ;;
        -helppath)
            COMPREPLY=( $(compgen -d ${cur}) )
            return 0
            ;;
        # patch file argument:
        -open)
            _filedir '@(pd|pat)'
            return 0
            ;;
        *)
            ;;
    esac

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    else
        _filedir '@(pd|pat)'
    fi
}
[ "${have:-}" ] &&  complete -F _pd-l2ork $filenames pd-l2ork
