#compdef chflags local flags args own='-g *(-u$EUID)' addflags() { for 1 2; do if [[ $1 = no* ]]; then flags+=("(${1#no})$1[set the $2 flag]" "($1)${1#no}[unset the $2 flag]") else flags+=("(no$1)$1[set the $2 flag]" "($1)no$1[unset the $2 flag]") fi done } addflags \ nodump nodump \ opaque opaque \ uappnd 'user append-only' \ uchg 'user immutable' if (( ! EUID )); then addflags \ arch archived \ sappnd 'system append-only' \ schg 'system immutable' unset own fi if [[ $OSTYPE = (freebsd|dragonfly|darwin)* ]]; then addflags \ hidden hidden \ uunlnk 'user undeletable' [[ $OSTYPE = freebsd* ]] && addflags \ offline offline \ rdonly readonly \ reparse 'Windows reparse point' \ sparse 'sparse file' \ system system (( EUID )) || addflags sunlnk 'system undeletable' args=( "-f[don't display diagnostic messages]" '-h[act on symlinks]' '-v[verbose output]' ) fi _arguments -s -A "-*" $args \ '(-L -P)-H[follow symlinks on the command line (specify with -R)]' \ '(-H -P)-L[follow all symlinks (specify with -R)]' \ '(-L -H)-P[do not follow symlinks (specify with -R)]' \ '-R[recurse directories]' \ ':file flag:_values -s , "file flags" $flags[@]' \ '*:file:_files "$own"'