#compdef git-smash

autoload -U is-at-least

_git-smash() {
    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[@]}" \
'--format=[Git log format to pretty print the targets]:FORMAT: ' \
'-n+[Limit number of listed commits (0 for unlimited stream)]:number: ' \
'--max-count=[Limit number of listed commits (0 for unlimited stream)]:number: ' \
'--recent=[List commits acquired from recent history (default 0)]:number: ' \
'--range=[Limit the listed commits to the given range]:revision-range: ' \
'--list[List mode to print all potential targets to stdout]' \
'--select[Select mode to print final target to stdout]' \
'-a[List all revs including already published commits]' \
'--all[List all revs including already published commits]' \
'-l[Limit the listed revs to local commits]' \
'--local[Limit the listed revs to local commits]' \
'--rebase[Rebase the fixup commit into the target]' \
'--no-rebase[Do not rebase the fixup commit into the target]' \
'-i[Let the user edit the list of commits before rebasing]' \
'--interactive[Let the user edit the list of commits before rebasing]' \
'--blame[List commits acquired from blame chunks]' \
'--no-blame[Do not list commits acquired from blame chunks]' \
'--files[List commits acquired from history of changed files]' \
'--no-files[Do not list commits acquired from history of changed files]' \
'--amend[Smash staged changes and refine the log message]' \
'--reword[Refine the log message ignoring all staged changes]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::commit -- Target commit to smash into:' \
":: :_git-smash_commands" \
"*::: :->git-smash" \
&& ret=0
    case $state in
    (git-smash)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:git-smash-command-$line[2]:"
        case $line[2] in
            (completions)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
":: :_git-smash__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_git-smash_commands] )) ||
_git-smash_commands() {
    local commands; commands=(
'completions:Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'git-smash commands' commands "$@"
}
(( $+functions[_git-smash__completions_commands] )) ||
_git-smash__completions_commands() {
    local commands; commands=()
    _describe -t commands 'git-smash completions commands' commands "$@"
}
(( $+functions[_git-smash__help_commands] )) ||
_git-smash__help_commands() {
    local commands; commands=(
'completions:Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'git-smash help commands' commands "$@"
}
(( $+functions[_git-smash__help__completions_commands] )) ||
_git-smash__help__completions_commands() {
    local commands; commands=()
    _describe -t commands 'git-smash help completions commands' commands "$@"
}
(( $+functions[_git-smash__help__help_commands] )) ||
_git-smash__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'git-smash help help commands' commands "$@"
}

if [ "$funcstack[1]" = "_git-smash" ]; then
    _git-smash "$@"
else
    compdef _git-smash git-smash
fi
