#compdef gitu

autoload -U is-at-least

_gitu() {
    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[@]}" : \
'-k+[Send keys on startup (eg\: \`gitu -k ll\`).     It is possible to send\:     - single char-keys\: a, b, c, ...     - special keys\: <backspace>, <enter>, <up>, <tab>, <delete>, <esc>, ...     - modifiers\: <ctrl+a>, <ctrl+shift+alt+a>, <shift+delete>]:KEYS:_default' \
'--keys=[Send keys on startup (eg\: \`gitu -k ll\`).     It is possible to send\:     - single char-keys\: a, b, c, ...     - special keys\: <backspace>, <enter>, <up>, <tab>, <delete>, <esc>, ...     - modifiers\: <ctrl+a>, <ctrl+shift+alt+a>, <shift+delete>]:KEYS:_default' \
'-c+[Config file to use]:CONFIG:_files' \
'--config=[Config file to use]:CONFIG:_files' \
'--print[Print one frame and exit. Useful for debugging]' \
'--log[Enable logging to '\''gitu.log'\'']' \
'--version[Print version]' \
'-h[Print help]' \
'--help[Print help]' \
":: :_gitu_commands" \
"*::: :->gitu" \
&& ret=0
    case $state in
    (gitu)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:gitu-command-$line[1]:"
        case $line[1] in
            (show)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':reference:_default' \
&& ret=0
;;
(blame)
_arguments "${_arguments_options[@]}" : \
'-r+[]:REV:_default' \
'--rev=[]:REV:_default' \
'-h[Print help]' \
'--help[Print help]' \
':file:_default' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" : \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':shell -- The shell to generate a completion script for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_gitu__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:gitu-help-command-$line[1]:"
        case $line[1] in
            (show)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(blame)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_gitu_commands] )) ||
_gitu_commands() {
    local commands; commands=(
'show:' \
'blame:' \
'completion:Print a shell completion script to stdout' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'gitu commands' commands "$@"
}
(( $+functions[_gitu__subcmd__blame_commands] )) ||
_gitu__subcmd__blame_commands() {
    local commands; commands=()
    _describe -t commands 'gitu blame commands' commands "$@"
}
(( $+functions[_gitu__subcmd__completion_commands] )) ||
_gitu__subcmd__completion_commands() {
    local commands; commands=()
    _describe -t commands 'gitu completion commands' commands "$@"
}
(( $+functions[_gitu__subcmd__help_commands] )) ||
_gitu__subcmd__help_commands() {
    local commands; commands=(
'show:' \
'blame:' \
'completion:Print a shell completion script to stdout' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'gitu help commands' commands "$@"
}
(( $+functions[_gitu__subcmd__help__subcmd__blame_commands] )) ||
_gitu__subcmd__help__subcmd__blame_commands() {
    local commands; commands=()
    _describe -t commands 'gitu help blame commands' commands "$@"
}
(( $+functions[_gitu__subcmd__help__subcmd__completion_commands] )) ||
_gitu__subcmd__help__subcmd__completion_commands() {
    local commands; commands=()
    _describe -t commands 'gitu help completion commands' commands "$@"
}
(( $+functions[_gitu__subcmd__help__subcmd__help_commands] )) ||
_gitu__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'gitu help help commands' commands "$@"
}
(( $+functions[_gitu__subcmd__help__subcmd__show_commands] )) ||
_gitu__subcmd__help__subcmd__show_commands() {
    local commands; commands=()
    _describe -t commands 'gitu help show commands' commands "$@"
}
(( $+functions[_gitu__subcmd__show_commands] )) ||
_gitu__subcmd__show_commands() {
    local commands; commands=()
    _describe -t commands 'gitu show commands' commands "$@"
}

if [ "$funcstack[1]" = "_gitu" ]; then
    _gitu "$@"
else
    compdef _gitu gitu
fi
