# bash completion for reicast-joyconfig
# Written by Claude Opus 5.5 <noreply@anthropic.com>, reviewed by Nicolas HOUDELOT.

_reicast_joyconfig()
{
    local cur prev words cword
    if declare -F _comp_initialize >/dev/null; then
        _comp_initialize -n := -- "$@" || return
    else
        _init_completion -n := || return
    fi

    case $prev in
        -h | --help)
            return
            ;;
        -d | --device-id)
            # the number X of /dev/input/eventX
            local dev ids=()
            for dev in /dev/input/event*; do
                [[ -e $dev ]] && ids+=("${dev#/dev/input/event}")
            done
            COMPREPLY=($(compgen -W '${ids[*]}' -- "$cur"))
            return
            ;;
        -f | --file)
            _filedir
            return
            ;;
    esac

    if [[ $cur == -* ]]; then
        COMPREPLY=($(compgen -W '-h --help -d --device-id -f --file' -- "$cur"))
    fi
} &&
    complete -F _reicast_joyconfig reicast-joyconfig
