#compdef yazi

autoload -U is-at-least

_yazi() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'--cwd-file=[Write the cwd on exit to this file]:CWD_FILE:_files' \
'--chooser-file=[Write the selected files to this file on open fired]:CHOOSER_FILE:_files' \
'--client-id=[Use the specified client ID, must be a globally unique number]:CLIENT_ID:_default' \
'--local-events=[Report the specified local events to stdout]:LOCAL_EVENTS:_default' \
'--remote-events=[Report the specified remote events to stdout]:REMOTE_EVENTS:_default' \
'--clear-cache[Clear the cache directory]' \
'--debug[Print debug information]' \
'-V[Print version]' \
'--version[Print version]' \
'-h[Print help]' \
'--help[Print help]' \
'*::entries -- Set the current working entry:_default' \
&& ret=0
}

(( $+functions[_yazi_commands] )) ||
_yazi_commands() {
    local commands; commands=()
    _describe -t commands 'yazi commands' commands "$@"
}

if [ "$funcstack[1]" = "_yazi" ]; then
    _yazi "$@"
else
    compdef _yazi yazi
fi
