#compdef touch

autoload -U is-at-least

_touch() {
    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[@]}" : \
'-t+[touch-help-timestamp]:STAMP:_default' \
'(-t)-d+[touch-help-date]:STRING:_default' \
'(-t)--date=[touch-help-date]:STRING:_default' \
'(-t)-r+[touch-help-reference]:FILE:_files' \
'(-t)--reference=[touch-help-reference]:FILE:_files' \
'--time=[touch-help-time]:WORD:(atime mtime)' \
'--help[touch-help-help]' \
'-a[touch-help-access]' \
'-f[(ignored)]' \
'-m[touch-help-modification]' \
'-c[touch-help-no-create]' \
'--no-create[touch-help-no-create]' \
'-h[touch-help-no-deref]' \
'--no-dereference[touch-help-no-deref]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_touch" ]; then
    _touch "$@"
else
    compdef _touch touch
fi
