diff options
author | dana <dana@dana.is> | 2018-01-03 16:13:23 -0600 |
---|---|---|
committer | Oliver Kiddle <opk@zsh.org> | 2018-01-04 00:16:43 +0100 |
commit | 1c4e7601c4b83322e8702954c2c3b8e4672026a3 (patch) | |
tree | dcc08a08daf81c0638330e65dd8469ed691b0ca7 /Completion/BSD | |
parent | 5f68531b5d8b1e6262f34e91bf047909f12dfeb2 (diff) | |
download | zsh-1c4e7601c4b83322e8702954c2c3b8e4672026a3.tar.gz zsh-1c4e7601c4b83322e8702954c2c3b8e4672026a3.tar.xz zsh-1c4e7601c4b83322e8702954c2c3b8e4672026a3.zip |
42210: factor out completion of file modes and flags and handle _comp_priv_prefix for chflags
Diffstat (limited to 'Completion/BSD')
-rw-r--r-- | Completion/BSD/Command/_chflags | 66 | ||||
-rw-r--r-- | Completion/BSD/Type/_flags | 70 |
2 files changed, 73 insertions, 63 deletions
diff --git a/Completion/BSD/Command/_chflags b/Completion/BSD/Command/_chflags index ddf61b25e..f97d1cdd1 100644 --- a/Completion/BSD/Command/_chflags +++ b/Completion/BSD/Command/_chflags @@ -1,68 +1,8 @@ #compdef chflags -local args flag_descs flags own='-g *(-u$EUID)' +local args own='-g *(-u$EUID)' -flag_descs=( - uappnd 'user append-only' - uchg 'user immutable' -) - -if (( ! EUID )); then - flag_descs+=( - arch archived - nodump nodump - sappnd 'system append-only' - schg 'system immutable' - ) - unset own -fi - -if [[ $OSTYPE = (darwin|dragonfly|freebsd|netbsd)* ]]; then - flag_descs+=(opaque opaque) - - if [[ $OSTYPE = darwin* ]]; then - flag_descs+=(hidden hidden) - fi - - if [[ $OSTYPE = (dragonfly|freebsd)* ]]; then - flag_descs+=(uunlnk 'user undeletable') - (( EUID )) || flag_descs+=(sunlnk 'system undeletable') - fi - - [[ $OSTYPE = dragonflybsd* ]] && { - flag_descs+=( - cache XXX - nouhistory 'user nohistory' - ) - - (( EUID )) || flag_descs+=( - noscache XXX - noshistory 'system nohistory' - ) - } - - [[ $OSTYPE = freebsd* ]] && flag_descs+=( - uarch archive - uhidden hidden - uoffline offline - urdonly 'DOS, Windows and CIFS readonly' - ureparse 'Windows reparse point' - usparse 'sparse file' - usystem 'DOS, Windows and CIFS system' - ) -fi - -() { - 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 -} $flag_descs +(( ! EUID || $+_comp_priv_prefix )) && own= if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then args=( @@ -72,7 +12,7 @@ if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then fi _arguments -s -A "-*" : $args \ - ':file flag:_values -s , "file flags" $flags[@]' \ + ': :_flags' \ '*:file:_files "$own"' \ - opth \ '-h[act on symlinks]' \ diff --git a/Completion/BSD/Type/_flags b/Completion/BSD/Type/_flags new file mode 100644 index 000000000..95044121c --- /dev/null +++ b/Completion/BSD/Type/_flags @@ -0,0 +1,70 @@ +#autoload + +# Provides completion for file flags (formerly part of _chflags) + +local curcontext=$curcontext su=$(( ! EUID || $+_comp_priv_prefix )) +local -a context line state state_descr copts=( "${@}" ) flags flag_descs +local -A val_args + +flag_descs+=( + uappnd 'user append-only' + uchg 'user immutable' +) + +if (( su )); then + flag_descs+=( + arch archived + nodump nodump + sappnd 'system append-only' + schg 'system immutable' + ) +fi + +if [[ $OSTYPE = (darwin|dragonfly|freebsd|netbsd)* ]]; then + flag_descs+=(opaque opaque) + + if [[ $OSTYPE = darwin* ]]; then + flag_descs+=(hidden hidden) + fi + + if [[ $OSTYPE = (dragonfly|freebsd)* ]]; then + flag_descs+=(uunlnk 'user undeletable') + + (( su )) && + flag_descs+=(sunlnk 'system undeletable') + fi + + if [[ $OSTYPE = dragonfly* ]]; then + flag_descs+=( + cache XXX + nouhistory 'user nohistory' + ) + + (( su )) && flag_descs+=( + noscache XXX + noshistory 'system nohistory' + ) + fi + + [[ $OSTYPE = freebsd* ]] && flag_descs+=( + uarch archive + uhidden hidden + uoffline offline + urdonly 'DOS, Windows and CIFS readonly' + ureparse 'Windows reparse point' + usparse 'sparse file' + usystem 'DOS, Windows and CIFS system' + ) +fi + +for 1 2 in $flag_descs; 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 + +_values -O copts -s , 'file flags' $flags |