PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/shadow

http://github.com/brinkman83/bashrc
#! | 501 lines | 406 code | 95 blank | 0 comment | 0 complexity | c62642a786329aa07702b0c09965a9e8 MD5 | raw file
  1# bash completion for shadow utils
  2
  3have useradd &&
  4_useradd()
  5{
  6    local cur prev split=false
  7
  8    COMPREPLY=()
  9    cur=`_get_cword`
 10    prev=${COMP_WORDS[COMP_CWORD-1]}
 11
 12    _split_longopt && split=true
 13
 14    # TODO: if -o/--non-unique is given, could complete on existing uids
 15    #       with -u/--uid
 16
 17    case "$prev" in
 18        -c|--comment|-h|--help|-e|--expiredate|-f|--inactive|-k|--key|-p|--password|-u|--uid|-Z|--selinux-user)
 19            return 0
 20            ;;
 21        -b|--base-dir|-d|--home|-k|--skel)
 22            _filedir -d
 23            return 0
 24            ;;
 25        -g|--gid)
 26            _gids
 27            [ -n "$bash205" ] && \
 28                COMPREPLY=( "${COMPREPLY[@]}" $( compgen -g ) )
 29            COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
 30            return 0
 31            ;;
 32        -G|--groups)
 33            [ -n "$bash205" ] && \
 34                COMPREPLY=( $( compgen -g -- "$cur" ) )
 35            return 0
 36            ;;
 37        -s|--shell)
 38            _shells
 39            return 0
 40            ;;
 41    esac
 42
 43    $split && return 0
 44
 45    if [[ "$cur" == -* ]]; then
 46        COMPREPLY=( $( compgen -W '-b --base-dir -c --comment -d --home\
 47            -D --defaults -e --expiredate -f --inactive -g --gid \
 48            -G --groups -h --help -k --skel -K --key -l -M \
 49            -m --create-home -N --no-user-group -o --non-unique \
 50            -p --password -r --system -s --shell -u --uid \
 51            -U --user-group -Z --selinux-user' -- "$cur" ) )
 52        return 0
 53    fi
 54} &&
 55complete -F _useradd useradd
 56
 57have usermod &&
 58_usermod()
 59{
 60    local cur prev split=false
 61
 62    COMPREPLY=()
 63    cur=`_get_cword`
 64    prev=${COMP_WORDS[COMP_CWORD-1]}
 65
 66    _split_longopt && split=true
 67
 68    # TODO: if -o/--non-unique is given, could complete on existing uids
 69    #       with -u/--uid
 70
 71    case "$prev" in
 72        -c|--comment|-d|--home|-e|--expiredate|-f|--inactive|-h|--help|-l|--login|-p|--password|-u|--uid|-Z|--selinux-user)
 73            return 0
 74            ;;
 75        -g|--gid)
 76            _gids
 77            [ -n "$bash205" ] && \
 78                COMPREPLY=( "${COMPREPLY[@]}" $( compgen -g ) )
 79            COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
 80            return 0
 81            ;;
 82        -G|--groups)
 83            [ -n "$bash205" ] && \
 84                COMPREPLY=( $( compgen -g -- "$cur" ) )
 85            return 0
 86            ;;
 87        -s|--shell)
 88            _shells
 89            return 0
 90            ;;
 91    esac
 92
 93    $split && return 0
 94
 95    if [[ "$cur" == -* ]]; then
 96        # TODO: -U/--unlock, -p/--password, -L/--lock mutually exclusive
 97        COMPREPLY=( $( compgen -W '-a --append -c --comment -d --home \
 98            -e --expiredate -f --inactive -g --gid -G --groups \
 99            -h --help -l --login -L --lock -o --non-unique \
100            -p --password -s --shell -u --uid -U --unlock \
101            -Z --selinux-user' -- "$cur" ) )
102        return 0
103    fi
104
105    COMPREPLY=( $( compgen -u -- "$cur" ) )
106} &&
107complete -F _usermod usermod
108
109have userdel &&
110_userdel()
111{
112    local cur
113
114    COMPREPLY=()
115    cur=`_get_cword`
116
117    if [[ "$cur" == -* ]]; then
118        COMPREPLY=( $( compgen -W '-f --force -h --help -r --remove' \
119            -- "$cur" ) )
120        return 0
121    fi
122
123    COMPREPLY=( $( compgen -u -- "$cur" ) )
124} &&
125complete -F _userdel userdel
126
127have chage &&
128_chage()
129{
130    local cur prev split=false
131
132    COMPREPLY=()
133    cur=`_get_cword`
134    prev=${COMP_WORDS[COMP_CWORD-1]}
135
136    _split_longopt && split=true
137
138    case "$prev" in
139        -d|--lastday|-E|--expiredate|-h|--help|-I|--inactive|-m|--mindays|-M|--maxdays|-W|--warndays)
140            return 0
141            ;;
142    esac
143
144    $split && return 0
145
146    if [[ "$cur" == -* ]]; then
147        COMPREPLY=( $( compgen -W '-d --lastday -E --expiredate \
148            -h --help -I --inactive -l --list -m --mindays \
149            -M --maxdays -W --warndays' -- "$cur" ) )
150        return 0
151    fi
152
153    COMPREPLY=( $( compgen -u -- "$cur" ) )
154} &&
155complete -F _chage chage
156
157have passwd &&
158_passwd()
159{
160    local cur prev
161
162    COMPREPLY=()
163    cur=`_get_cword`
164    prev=${COMP_WORDS[COMP_CWORD-1]}
165
166    case "$prev" in
167        -n|-x|-w|-i|-\?|--help|--usage)
168            return 0
169            ;;
170    esac
171
172    if [[ "$cur" == -* ]]; then
173        COMPREPLY=( $( compgen -W '-k -l --stdin -u -d -n -x -w -i -S \
174            -? --help --usage' -- "$cur" ) )
175        return 0
176    fi
177
178    COMPREPLY=( $( compgen -u -- "$cur" ) )
179} &&
180complete -F _passwd passwd
181
182have chpasswd &&
183_chpasswd()
184{
185    local cur prev split=false
186
187    COMPREPLY=()
188    cur=`_get_cword`
189    prev=${COMP_WORDS[COMP_CWORD-1]}
190
191    _split_longopt && split=true
192
193    case "$prev" in
194        -c|--crypt)
195            COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
196                -- "$cur" ) )
197            return 0
198            ;;
199        -s|--sha-rounds)
200            return 0
201            ;;
202    esac
203
204    $split && return 0
205
206    if [[ "$cur" == -* ]]; then
207        COMPREPLY=( $( compgen -W '-c --crypt-method -e --encrypted \
208            -h --help -m --md5 -s --sha-rounds' -- "$cur" ) )
209        return 0
210    fi
211} &&
212complete -F _chpasswd chpasswd
213
214have newusers &&
215_newusers()
216{
217    local cur prev split=false
218
219    COMPREPLY=()
220    cur=`_get_cword`
221    prev=${COMP_WORDS[COMP_CWORD-1]}
222
223    _split_longopt && split=true
224
225    case "$prev" in
226        -c|--crypt)
227            COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
228                -- "$cur" ) )
229            return 0
230            ;;
231        -s|--sha-rounds)
232            return 0
233            ;;
234    esac
235
236    $split && return 0
237
238    if [[ "$cur" == -* ]]; then
239        COMPREPLY=( $( compgen -W '-c --crypt-method --r --system \
240            -s --sha-rounds' -- "$cur" ) )
241        return 0
242    fi
243
244    _filedir
245} &&
246complete -F _newusers $filenames newusers
247
248have pwck &&
249_pwck()
250{
251    local cur
252
253    COMPREPLY=()
254    cur=`_get_cword`
255
256    if [[ "$cur" == -* ]]; then
257        COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) )
258        return 0
259    fi
260
261    _filedir
262} &&
263complete -F _pwck $filenames pwck
264
265have groupadd &&
266_groupadd()
267{
268    local cur prev split=false
269
270    COMPREPLY=()
271    cur=`_get_cword`
272    prev=${COMP_WORDS[COMP_CWORD-1]}
273
274    _split_longopt && split=true
275
276    # TODO: if -o/--non-unique is given, could complete on existing gids
277    #       with -g/--gid
278
279    case "$prev" in
280        -g|--gid|-K|--key|-p|--password)
281            return 0
282            ;;
283    esac
284
285    $split && return 0
286
287    if [[ "$cur" == -* ]]; then
288        COMPREPLY=( $( compgen -W '-f --force -g --gid -h --help \
289            -K --key -o --non-unique -p --password -r --system' \
290            -- "$cur" ) )
291        return 0
292    fi
293} &&
294complete -F _groupadd groupadd
295
296have groupmod &&
297_groupmod()
298{
299    local cur prev split=false
300
301    COMPREPLY=()
302    cur=`_get_cword`
303    prev=${COMP_WORDS[COMP_CWORD-1]}
304
305    _split_longopt && split=true
306
307    # TODO: if -o/--non-unique is given, could complete on existing gids
308    #       with -g/--gid
309
310    case "$prev" in
311        -g|--gid|-h|--help|-n|--new-name|-p|--password)
312            return 0
313            ;;
314    esac
315
316    $split && return 0
317
318    if [[ "$cur" == -* ]]; then
319        COMPREPLY=( $( compgen -W '-g --gid -h --help -n --new-name \
320            -o --non-unique -p --password' -- "$cur" ) )
321        return 0
322    fi
323
324    [ -n "$bash205" ] && COMPREPLY=( $( compgen -g -- "$cur" ) )
325} &&
326complete -F _groupmod groupmod
327
328[ -n "$bash205" ] && complete -g groupdel
329
330have newgrp &&
331_newgrp()
332{
333    COMPREPLY=()
334    if [[ "`_get_cword`" == "-" ]]; then
335        COMPREPLY=( - )
336    fi
337} &&
338complete ${bash205:+-g} -F _newgrp newgrp
339
340have gpasswd &&
341_gpasswd()
342{
343    local cur prev
344
345    COMPREPLY=()
346    cur=`_get_cword`
347    prev=${COMP_WORDS[COMP_CWORD-1]}
348
349    case "$prev" in
350        -a|-d|-A|-M)
351            COMPREPLY=( $( compgen -u -- "$cur" ) )
352            return 0
353            ;;
354    esac
355
356    if [[ "$cur" == -* ]]; then
357        COMPREPLY=( $( compgen -W '-a -d -r -R -A -M' -- "$cur" ) )
358        return 0
359    fi
360
361    [ -n "$bash205" ] && COMPREPLY=( $( compgen -g -- "$cur" ) )
362} &&
363complete -F _gpasswd gpasswd
364
365have groupmems &&
366_groupmems()
367{
368    local cur prev
369
370    COMPREPLY=()
371    cur=`_get_cword`
372    prev=${COMP_WORDS[COMP_CWORD-1]}
373
374    case "$prev" in
375        -a|-d)
376            COMPREPLY=( $( compgen -u -- "$cur" ) )
377            return 0
378            ;;
379        -g)
380            [ -n "$bash205" ] && \
381                COMPREPLY=( $( compgen -g -- "$cur" ) )
382            return 0
383            ;;
384    esac
385
386    if [[ "$cur" == -* ]]; then
387        COMPREPLY=( $( compgen -W '-a -d -p -g -l' -- "$cur" ) )
388        return 0
389    fi
390} &&
391complete -F _groupmems groupmems
392
393have grpck &&
394_grpck()
395{
396    local cur
397
398    COMPREPLY=()
399    cur=`_get_cword`
400
401    if [[ "$cur" == -* ]]; then
402        COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) )
403        return 0
404    fi
405
406    _filedir
407} &&
408complete -F _grpck $filenames grpck
409
410have vipw || have vigr &&
411_vipw()
412{
413    local cur prev
414
415    COMPREPLY=()
416    cur=`_get_cword`
417    prev=${COMP_WORDS[COMP_CWORD-1]}
418
419    case "$prev" in
420        -h|--help)
421            return 0
422            ;;
423    esac
424
425    if [[ "$cur" == -* ]]; then
426        COMPREPLY=( $( compgen -W '-g --group -h --help -p --passwd \
427            -q --quiet -s --shadow' -- "$cur" ) )
428        return 0
429    fi
430} &&
431complete -F _vipw vipw vigr
432
433have faillog &&
434_faillog()
435{
436    local cur prev split=false
437
438    COMPREPLY=()
439    cur=`_get_cword`
440    prev=${COMP_WORDS[COMP_CWORD-1]}
441
442    _split_longopt && split=true
443
444    case "$prev" in
445        -h|--help|-l|--lock-time|-m|--maximum|-t|--time)
446            return 0
447            ;;
448        -u|--user)
449            COMPREPLY=( $( compgen -u -- "$cur" ) )
450            return 0
451            ;;
452    esac
453
454    $split && return 0
455
456    if [[ "$cur" == -* ]]; then
457        COMPREPLY=( $( compgen -W '-a --all -h --help -l --lock-time \
458            -m --maximum -r --reset -t --time -u --user' -- "$cur" ) )
459        return 0
460    fi
461} &&
462complete -F _faillog faillog
463
464have lastlog &&
465_lastlog()
466{
467    local cur prev split=false
468
469    COMPREPLY=()
470    cur=`_get_cword`
471    prev=${COMP_WORDS[COMP_CWORD-1]}
472
473    _split_longopt && split=true
474
475    case "$prev" in
476        -b|--before|-h|--help|-t|--time)
477            return 0
478            ;;
479        -u|--user)
480            COMPREPLY=( $( compgen -u -- "$cur" ) )
481            return 0
482            ;;
483    esac
484
485    $split && return 0
486
487    if [[ "$cur" == -* ]]; then
488        COMPREPLY=( $( compgen -W '-b --before -h --help -t --time \
489            -u --user' -- "$cur" ) )
490        return 0
491    fi
492} &&
493complete -F _lastlog lastlog
494
495# Local variables:
496# mode: shell-script
497# sh-basic-offset: 4
498# sh-indent-comment: t
499# indent-tabs-mode: nil
500# End:
501# ex: ts=4 sw=4 et filetype=sh