summary refs log tree commit diff
path: root/Completion/BSD/Command/_chflags
blob: ddf61b25e9f772d4ac79ef3da39640f2f18e711f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#compdef chflags

local args flag_descs flags 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

if [[ $OSTYPE = (darwin|dragonfly|freebsd)* ]]; then
  args=(
    "-f[don't display diagnostic messages]"
    '-v[verbose output]'
  )
fi

_arguments -s -A "-*" : $args \
  ':file flag:_values -s , "file flags" $flags[@]' \
  '*:file:_files "$own"' \
  - opth \
  '-h[act on symlinks]' \
  - optR \
  '-R[recurse directories]' \
  '(-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)]'