#compdef ls

autoload -U is-at-least

_ls() {
    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[@]}" : \
'--format=[ls-help-set-display-format]: :(long verbose single-column columns vertical across horizontal commas)' \
'-T+[ls-help-assume-tab-stops]:COLS:_default' \
'--tabsize=[ls-help-assume-tab-stops]:COLS:_default' \
'--hyperlink=[ls-help-hyperlink-filenames]' \
'--quoting-style=[ls-help-set-quoting-style]: :(literal shell shell-escape shell-always shell-escape-always c escape)' \
'--time=[ls-help-show-time-field]:field:(atime ctime mtime birth)' \
'*--hide=[ls-help-hide-pattern]:PATTERN:_default' \
'*-I+[ls-help-ignore-pattern]:PATTERN:_default' \
'*--ignore=[ls-help-ignore-pattern]:PATTERN:_default' \
'--sort=[ls-help-sort-by-field]:field:(name none time size version extension width)' \
'--block-size=[ls-help-block-size]:BLOCK_SIZE:_default' \
'-w+[ls-help-terminal-width]:COLS:_default' \
'--width=[ls-help-terminal-width]:COLS:_default' \
'--color=[ls-help-color-output]' \
'--indicator-style=[ls-help-indicator-style]: :(none slash file-type classify)' \
'-F+[ls-help-classify]' \
'--classify=[ls-help-classify]' \
'--time-style=[ls-help-time-style]:TIME_STYLE:_default' \
'--help[ls-help-print-help]' \
'-C[ls-help-display-files-columns]' \
'-l[ls-help-display-detailed-info]' \
'--long[ls-help-display-detailed-info]' \
'-x[ls-help-list-entries-rows]' \
'-m[ls-help-list-entries-commas]' \
'--zero[ls-help-list-entries-nul]' \
'-D[ls-help-generate-dired-output]' \
'--dired[ls-help-generate-dired-output]' \
'-1[ls-help-list-one-file-per-line]' \
'-o[ls-help-long-format-no-group]' \
'-g[ls-help-long-no-owner]' \
'-n[ls-help-long-numeric-uid-gid]' \
'--numeric-uid-gid[ls-help-long-numeric-uid-gid]' \
'-N[ls-help-literal-quoting-style]' \
'--literal[ls-help-literal-quoting-style]' \
'-b[ls-help-escape-quoting-style]' \
'--escape[ls-help-escape-quoting-style]' \
'-Q[ls-help-c-quoting-style]' \
'--quote-name[ls-help-c-quoting-style]' \
'-q[ls-help-replace-control-chars]' \
'--hide-control-chars[ls-help-replace-control-chars]' \
'--show-control-chars[ls-help-show-control-chars]' \
'-c[ls-help-time-change]' \
'-u[ls-help-time-access]' \
'-B[ls-help-ignore-backups]' \
'--ignore-backups[ls-help-ignore-backups]' \
'-S[ls-help-sort-by-size]' \
'-t[ls-help-sort-by-time]' \
'-v[ls-help-sort-by-version]' \
'-X[ls-help-sort-by-extension]' \
'-U[ls-help-sort-none]' \
'-L[ls-help-dereference-all]' \
'--dereference[ls-help-dereference-all]' \
'--dereference-command-line-symlink-to-dir[ls-help-dereference-dir-args]' \
'-H[ls-help-dereference-args]' \
'--dereference-command-line[ls-help-dereference-args]' \
'-G[ls-help-no-group]' \
'--no-group[ls-help-no-group]' \
'--author[ls-help-author]' \
'-a[ls-help-all-files]' \
'--all[ls-help-all-files]' \
'-A[ls-help-almost-all]' \
'--almost-all[ls-help-almost-all]' \
'-d[ls-help-directory]' \
'--directory[ls-help-directory]' \
'-h[ls-help-human-readable]' \
'--human-readable[ls-help-human-readable]' \
'-k[ls-help-kibibytes]' \
'--kibibytes[ls-help-kibibytes]' \
'--si[ls-help-si]' \
'-i[ls-help-print-inode]' \
'--inode[ls-help-print-inode]' \
'-r[ls-help-reverse-sort]' \
'--reverse[ls-help-reverse-sort]' \
'-R[ls-help-recursive]' \
'--recursive[ls-help-recursive]' \
'-s[ls-help-allocation-size]' \
'--size[ls-help-allocation-size]' \
'--file-type[ls-help-file-type]' \
'-p[ls-help-slash-directories]' \
'--full-time[ls-help-full-time]' \
'-Z[ls-help-context]' \
'--context[ls-help-context]' \
'--group-directories-first[ls-help-group-directories-first]' \
'-V[Print version]' \
'--version[Print version]' \
'::paths:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_ls" ]; then
    _ls "$@"
else
    compdef _ls ls
fi
