# bash completion for Crispy Doom               -*- shell-script -*-

_crispy_doom()
{
    local cur prev words cword
    _init_completion || return

    # Save the previous switch on the command line in the prevsw variable
    local i prevsw=""
    for (( i=1; $cword > 1 && i <= $cword; i++ )); do
        if [[ ${words[i]} == -* ]]; then
            prevsw=${words[i]}
        fi
    done

    # Allow adding more than one file with the same extension to the same switch
    case $prevsw in
        -config|-extraconfig)
            _filedir cfg
            ;;
        -file|-iwad|-aa|-af|-as|-merge|-nwtmerge)
            _filedir wad
            ;;
        -playdemo|-timedemo)
            _filedir lmp
            ;;
        -deh)
            _filedir '@(bex|deh)'
            ;;
    esac

    case $prev in
        -pack)
            COMPREPLY=(doom2 tnt plutonia)
            ;;
        -gameversion)
            COMPREPLY=(1.666 1.7 1.8 1.9 ultimate final final2 hacx chex)
            ;;
        -setmem)
            COMPREPLY=(dos622 dos71 dosbox)
            ;;
    esac

    if [[ $cur == -* ]]; then
        COMPREPLY=( $( compgen -W '-config -devparm -extraconfig -file -iwad -nomusic -nomusicpacks -nosfx -nosound -response -savedir -version
-coop_spawns -doubleammo -episode -fast -loadgame -nomonsters -pistolstart -respawn -skill -turbo -warp
-1 -2 -3 -display -fullscreen -geometry -height -noblit -nodraw -nograbmouse -nomouse -width -window
-altdeath -autojoin -avg -connect -deathmatch -dedicated -dm3 -dup -extratics -left -localsearch -nodes -oldsync -port -privateserver -query -right -search -server -servername -solo-net -timer
-aa -af -as -deh -lumpdump -merge -mergedump -noautoload -nocheats -nodeh -nodehlump -nosideload -nwtmerge
-longtics -maxdemo -playdemo -record -shorttics -strictdemos -timedemo
-donut -gameversion -pack -setmem -spechit -statdump
-cdrom -dumpsubstconfig -mb -mmap -nogui
' -- "$cur" ) )
    fi
} &&

complete -F _crispy_doom crispy-doom

# ex: ts=4 sw=4 et filetype=sh
