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

_Russian_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
        -file|-iwad|-aa|-af|-as|-nwtmerge)
            _filedir wad
            ;;
        -deh)
            _filedir '@(bex|deh)'
            ;;
    esac

    case $prev in
        -config)
            _filedir ini
            ;;
        -response)
            _filedir txt
            ;;
        -gus_patches|-savedir)
            _filedir -d
            ;;
        -playdemo|-timedemo|-record)
            _filedir lmp
            ;;
        -lang)
            COMPREPLY=( $( compgen -W 'en ru' -- "$cur" ) )
            ;;
        -setmem)
            COMPREPLY=( $( compgen -W 'dos622 dos71 dosbox' -- "$cur" ))
            ;;
        -pack)
            COMPREPLY=( $( compgen -W 'doom2 tnt plutonia' -- "$cur" ))
            ;;
        -gameversion)
            COMPREPLY=( $( compgen -W '1.666 1.7 1.8 1.9 ultimate doomse final final2' -- "$cur" ))
            ;;
    esac

    if [[ $cur == -* ]]; then
        COMPREPLY=( $( compgen -W '-h --help --Version -lang -iwad -file -deh -nocheats -nodeh -nodehlump -nwtmerge -af -as -aa -autoloadroot -noautoload -response -gus_patches -config -savedir -cdrom -loadgame -skill -map -warp -map -warp -episode -nomonsters -respawn -fast -coop_spawns -turbo -vanilla -beta -jaguar -pack -gameversion -complevel -mb -setmem -donut -reject_pad_with_ff -blockmap -mmap -fullscreen -window -nofullscreen -width -height -geometry -1 -2 -3 -devparm -nogui -nosound -nosfx -nomusic -noblit -nomouse -nograbmouse -playdemo -timedemo -nodraw -record -maxdemo -strictdemos -statdump -longtics -shorttics -autojoin -connect -drone -solo-net -server -privateserver -dedicated -port -servername -nodes -ignoreversion -newsync -extratics -dup -avg -deathmatch -altdeath -dm3 -timer -left -right -search -query -localsearch' -- "$cur" ) )
    fi
} &&

complete -F _Russian_Doom russian-doom

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