Initial creation of pw completion
[zfbsd.git] / _pw
blobcf1263135570f4544364410568eff4a9a9732e72
1 #compdef pw
3 _pw() {
4   local tmp common_args user_cmn_args
5   common_args=(
6   "-V[Set the alternate location for /etc]:Alternate etc dir:_files -/"
7   '-C[Specify a different configuration file]:Configuration file:_files -g "*.conf"'
8   '-q[Suppress rrror messages]'
9   )
10   user_cmn_args=(
11   '-n[Specify the name]:name:'
12   '-u[Specify the uid]:uid:'
13   )
14   _arguments -s  \
15   '*::command:->commands' && ret=0
16   while [[ -n "$state" ]]; do
17     tmp="$state"
18     state=
19     case "$tmp" in
20       commands)
21       if (( CURRENT == 1 )); then
22         state=subcommands
23       else
24         case "$words[1]" in 
25           useradd)
26           ;;
27           userdel)
28           _arguments \
29           $common_args \
30           $user_cmn_args \
31           "-r[Remove the user's home directory]" \
32           "-Y[allow automatic updating of NIS database]" \
33           ":Name or uid:_users" 
34           ;;
35           usermod)
36           local shells
37           if [[ -r /etc/shells ]]; then
38             shells=( ${${(f)"$(</etc/shells)"}:#\#*} )
39           else
40             shells=( ${(M)commands:#*/(|[abckz]|tc|ba)sh} )
41           fi
43           _arguments \
44           $common_args \
45           "-Y[allow automatic updating of NIS database]" \
46           '-n[Specify the name]:name:' \
47           '-u[Specify the uid]:uid:' \
48           '-c[Modify the comment]:comment:' \
49           "-d[Modify the home directory location]:home dir:_directories -W /" \
50           "-e[Modify the expiration date]:date:" \
51           "-p[Modify the password expiration date]:date:" \
52           "-g[Modify the main group]:group:_groups" \
53           "-G[Modify supplementary groups]:groups:_groups -S," \
54           "-l[Modify the user name]:name:" \
55           "-m[Attempt to create the user's directory]" \
56           "-M[Create the user’s home directory with the specified mode]:mode:" \
57           "-k[Skeleton for the home directory creation]:skeleton dir:_directories -W /" \
58           "-w[sets the default method used to set passwords]:methods:((no\:disable\ login yes\:force\ the\ password\ to\ be\ the\ account\ name none\:force\ a\ blank\ password random\:generate\ a\ random\ password))" \
59           "-s[specify the user shell]:shell:( $shells /sbin/nologin )" \
60           "-L[Set the login class]:class:" \
61           ":Name or uid:_users"
62           ;;
63           usershow)
64           _arguments \
65           $common_args \
66           '-n[Specify the name]:name:' \
67           '-u[Specify the uid]:uid:' \
68           "-F[forces pw to print the details of an account]" \
69           "-P[outputs the account details in a more human readable form]" \
70           "-7[show account details in v7 format]" \
71           "-a[lists all users currently on file]" \
72           ":Name|uid:_users"
74           ;;
75           (user|group)next)
76                 return 0
77           ;;
78           groupadd)
79           _arguments \
80           $common_args \
81           $user_cmn_args
82           ;;
83           groupdel)
84           _arguments \
85           $common_args \
86           $user_cmn_args
87           ;;
88           groupmod)
89           _arguments \
90           $common_args \
91           $user_cmn_args
92           ;;
93           groupshow)
94           _arguments \
95           $common_args \
96           $user_cmn_args
97           ;;
98           lock|unlock)
99           _arguments \
100           $common_args \
101           ":User to $words[1]:_users"
102           ;;
103           *)
104           _message 'command not found'
105           ;;
106         esac
107       fi
108       ;;
109       subcommands)
110       subcmds=(
111       'useradd[Add a user]'
112       'userdel[Delete a user]'
113       'usermod[Modify a user]'
114       'usershow[Show informations about a user]'
115       'usernext'
116       'groupdadd[Add a group]'
117       'groupdel[Delete a group]'
118       'groupmod[Modify a group]'
119       'groupshow[Show information about a group]'
120       'groupnext'
121       'lock[lock a user]'
122       'unlock[unlock a user]'
123       )
124       _values "pw command" $subcmds && return 0
125       ;;
126     esac
127   done
130 _pw "$@"