summaryrefslogtreecommitdiffstats
path: root/completions/useradd
blob: 6c0bef1526c4734c2ee4289ea3f5e3ef4d0da475 (plain)
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
# useradd(8) completion                                    -*- shell-script -*-

_comp_cmd_useradd()
{
    local cur prev words cword was_split comp_args
    _comp_initialize -s -- "$@" || return

    # TODO: if -o/--non-unique is given, could complete on existing uids
    #       with -u/--uid

    local word chroot="" has_chroot=""
    for word in "${words[@]}"; do
        if [[ $has_chroot ]]; then
            chroot=$word
            break
        fi
        [[ $word != -@(R|-root) ]] || has_chroot=set
    done

    local noargopts='!(-*|*[cefKpubdkRgGZs]*)'
    # shellcheck disable=SC2254
    case $prev in
        --comment | --help | --expiredate | --inactive | --key | --password | \
            --uid | -${noargopts}[chefKpu])
            return
            ;;
        --base-dir | --home-dir | --skel | --root | -${noargopts}[bdkR])
            _comp_compgen_filedir -d
            return
            ;;
        --gid | -${noargopts}g)
            _comp_compgen_gids
            _comp_compgen -a -- -g
            return
            ;;
        --groups | -${noargopts}G)
            _comp_delimited , -g
            return
            ;;
        --selinux-user | -${noargopts}Z)
            _comp_compgen_selinux_users
            return
            ;;
        --shell | -${noargopts}s)
            _comp_compgen_shells "${chroot-}"
            return
            ;;
    esac

    [[ $was_split ]] && return

    [[ $cur == -* ]] &&
        _comp_compgen_help
} &&
    complete -F _comp_cmd_useradd useradd

# ex: filetype=sh