#compdef who

autoload -U is-at-least

_who() {
    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[@]}" : \
'-a[same as -b -d --login -p -r -t -T -u]' \
'--all[same as -b -d --login -p -r -t -T -u]' \
'-b[time of last system boot]' \
'--boot[time of last system boot]' \
'-d[print dead processes]' \
'--dead[print dead processes]' \
'-H[print line of column headings]' \
'--heading[print line of column headings]' \
'-l[print system login processes]' \
'--login[print system login processes]' \
'--lookup[attempt to canonicalize hostnames via DNS]' \
'-m[only hostname and user associated with stdin]' \
'-p[print active processes spawned by init]' \
'--process[print active processes spawned by init]' \
'-q[all login names and number of users logged on]' \
'--count[all login names and number of users logged on]' \
'-r[print current runlevel]' \
'--runlevel[print current runlevel]' \
'-s[print only name, line, and time (default)]' \
'--short[print only name, line, and time (default)]' \
'-t[print last system clock change]' \
'--time[print last system clock change]' \
'-u[list users logged in]' \
'--users[list users logged in]' \
'-T[add user'\''s message status as +, - or ?]' \
'-w[add user'\''s message status as +, - or ?]' \
'--mesg[add user'\''s message status as +, - or ?]' \
'--message[add user'\''s message status as +, - or ?]' \
'--writable[add user'\''s message status as +, - or ?]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::FILE:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_who" ]; then
    _who "$@"
else
    compdef _who who
fi
