#compdef realpath

autoload -U is-at-least

_realpath() {
    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[@]}" : \
'--relative-to=[realpath-help-relative-to]:DIR:_default' \
'--relative-base=[realpath-help-relative-base]:DIR:_default' \
'-q[realpath-help-quiet]' \
'--quiet[realpath-help-quiet]' \
'-s[realpath-help-strip]' \
'--strip[realpath-help-strip]' \
'--no-symlinks[realpath-help-strip]' \
'-z[realpath-help-zero]' \
'--zero[realpath-help-zero]' \
'-L[realpath-help-logical]' \
'--logical[realpath-help-logical]' \
'-P[realpath-help-physical]' \
'--physical[realpath-help-physical]' \
'-e[realpath-help-canonicalize-existing]' \
'--canonicalize-existing[realpath-help-canonicalize-existing]' \
'-m[realpath-help-canonicalize-missing]' \
'--canonicalize-missing[realpath-help-canonicalize-missing]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_realpath" ]; then
    _realpath "$@"
else
    compdef _realpath realpath
fi
