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

_Russian_Heretic()
{
    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" ))
            ;;
        -hhever)
            COMPREPLY=( $( compgen -W '1.0 1.2 1.3' -- "$cur" ))
            ;;
    esac

    if [[ $cword -ge 3 && ${words[$(cword - 2)]} == '-recordfrom' ]]; then
        _filedir lmp
    fi

    if [[ $cur == -* ]]; then
        COMPREPLY=( $( compgen -W '-h --help --Version -lang -iwad -file -deh -nocheats -nwtmerge -af -as -aa -autoloadroot -noautoload -response -gus_patches -config -savedir -cdrom -loadgame -skill -map -warp -episode -nomonsters -respawn -fast -coop_spawns -vanilla -hhever -mb -setmem -reject_pad_with_ff -blockmap -mmap -fullscreen -window -nofullscreen -width -height -geometry -1 -2 -3 -devparm -nogui -nosound -nosfx -nomusic -noblit -nomouse -nograbmouse -ravpic -playdemo -timedemo -record -recordfrom -maxdemo -strictdemos -demoextend -longtics -shortticfix -autojoin -connect -drone -solo-net -server -privateserver -port -servername -nodes -ignoreversion -newsync -extratics -dup -deathmatch -timer' -- "$cur" ) )
    fi
} &&

complete -F _Russian_Heretic russian-heretic

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