#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+[use \[\[CC\]YY\]MMDDhhmm\[.ss\] instead of the current time]:STAMP:_default' \
'(-t)-d+[parse argument and use it instead of current time]:STRING:_default' \
'(-t)--date=[parse argument and use it instead of current time]:STRING:_default' \
'(-t)-r+[use this file'\''s times instead of the current time]:FILE:_files' \
'(-t)--reference=[use this file'\''s times instead of the current time]:FILE:_files' \
'--time=[change only the specified time\: "access", "atime", or "use" are equivalent to -a; "modify" or "mtime" are equivalent to -m]:WORD:(atime mtime)' \
'--help[Print help information.]' \
'-a[change only the access time]' \
'-f[(ignored)]' \
'-m[change only the modification time]' \
'-c[do not create any files]' \
'--no-create[do not create any files]' \
'-h[affect each symbolic link instead of any referenced file (only for systems that can change the timestamps of a symlink)]' \
'--no-dereference[affect each symbolic link instead of any referenced file (only for systems that can change the timestamps of a symlink)]' \
'-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
