#compdef mktemp

autoload -U is-at-least

_mktemp() {
    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[@]}" : \
'--suffix=[append SUFFIX to TEMPLATE; SUFFIX must not contain a path separator. This option is implied if TEMPLATE does not end with X.]:SUFFIX:_default' \
'-p+[short form of --tmpdir]:DIR:_files -/' \
'--tmpdir=[interpret TEMPLATE relative to DIR; if DIR is not specified, use \$TMPDIR (\$TMP on windows) if set, else /tmp. With this option, TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE may contain slashes, but mktemp creates only the final component]::DIR:_files -/' \
'-d[Make a directory instead of a file]' \
'--directory[Make a directory instead of a file]' \
'-u[do not create anything; merely print a name (unsafe)]' \
'--dry-run[do not create anything; merely print a name (unsafe)]' \
'-q[Fail silently if an error occurs.]' \
'--quiet[Fail silently if an error occurs.]' \
'-t[Generate a template (using the supplied prefix and TMPDIR (TMP on windows) if set) to create a filename template \[deprecated\]]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::template:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_mktemp" ]; then
    _mktemp "$@"
else
    compdef _mktemp mktemp
fi
