about summary refs log tree commit diff
path: root/Completion/Unix/Command/_user_admin
blob: 31ccbf1c24021de85458c887781e11082ad6589f (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
#compdef useradd usermod groupadd groupmod

local args shells home=${${words[(r)-D]:+b}:-d} sun redhat

[[ -e /etc/redhat-release || -e /etc/mandrake-release ]]
redhat=$?

if [[ $service = user* ]]; then
  if [[ -r /etc/shells ]]; then
    shells=( ${${(f)"$(</etc/shells)"}:#\#*} )
  else
    shells=( ${(M)commands:#*/(|[abckz]|tc|ba)sh} )
  fi

  args=(
    '(-D)-c+[comment]:comment'
    "(-D)-${home}+[home directory]:home directory:_directories -W /"
    '(-D)-e+[specify expiration date]:expiration date (YYYY-MM-DD)'
    '(-D)-f+[specify inactive days]:inactive days'
    '(-D)-g+[initial group]:initial group:_groups'
    '(-D)-G+[supplementary groups]:supplementary group:_groups -S,'
    "(-D)-s+[shell]:shell:( $shells /bin/false )"
    '(-D -M)-m[create home directory]'
    '(-D)-u[uid]:uid'
    '(-D)-o[allow non unique uid]'
  )
  [[ $OSTYPE = linux* ]] && args+=(
      '(-D -U -L)-p+[specify encrypted password]:encrypted password' )

  if [[ $service = useradd ]]; then
    (( redhat )) || args+=(
      "(-D -k -m)-M[don't create home]"
      '(-D)-r[create system account]'
      "(-D)-n[don't create mirrored user]"
    )
    [[ $OSTYPE = linux* ]] || sun=" -s"
    args+=(
      "(-c -G -m -k -M -p -u -o -n -r$sun)-D[modify or display defaults]"
      '(-D -M)-k[skeleton home directory]:skeleton directory:_directories -W /'
      ':username'
    )
  else
    (( redhat )) || args=( $args[@]
	"(-U -p)-L[lock user's password]"
	"(-L -p)-U[unlock user's password]"
    )
    args+=(
      '-a[append groups]'
      '-l[specify new user name]:new username'
      ':username:_users'
    )
  fi
else
  args=( '-g+[gid]:gid' '-o[allow non unique gid]' )
  if [[ $service = groupadd ]]; then
    args+=( ':group name' )
    (( redhat )) || args=( $args[@]
      '-r[create system group]'
      '-f[force]'
    )
  else
    args+=(
      '-n[specify new group name]:new group name'
      ':group:_groups'
    )
  fi
fi

_arguments -A "-*" -s $args[@]