#compdef rm

autoload -U is-at-least

_rm() {
    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[@]}" : \
'--interactive=[prompt according to WHEN\: never, once (-I), or always (-i). Without WHEN, prompts always]::WHEN:(always once never)' \
'--preserve-root=[do not remove '\''/'\'' (default); with '\''all'\'', reject any command line argument on a separate device from its parent]::all:(all)' \
'-f[ignore nonexistent files and arguments, never prompt]' \
'--force[ignore nonexistent files and arguments, never prompt]' \
'-i[prompt before every removal]' \
'-I[prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving some protection against most mistakes]' \
'--one-file-system[when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument (NOT IMPLEMENTED)]' \
'--no-preserve-root[do not treat '\''/'\'' specially]' \
'-r[remove directories and their contents recursively]' \
'-R[remove directories and their contents recursively]' \
'--recursive[remove directories and their contents recursively]' \
'-d[remove empty directories]' \
'--dir[remove empty directories]' \
'-v[explain what is being done]' \
'--verbose[explain what is being done]' \
'-g[display a progress bar. Note\: this feature is not supported by GNU coreutils.]' \
'--progress[display a progress bar. Note\: this feature is not supported by GNU coreutils.]' \
'--presume-input-tty[]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_rm" ]; then
    _rm "$@"
else
    compdef _rm rm
fi
