summaryrefslogtreecommitdiff
path: root/completions/quota
blob: f5f9cc824ddb8355746f2efd887e1d4ed71bced5 (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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# bash completion for quota-tools                          -*- shell-script -*-

_user_or_group()
{
    local i

    # complete on groups if -g was given
    for ((i = 1; i < cword; i++)); do
        if [[ ${words[i]} == -@(g|-group) ]]; then
            COMPREPLY=($(compgen -g -- "$cur"))
            return
        fi
    done

    # otherwise complete on users
    COMPREPLY=($(compgen -u -- "$cur"))
}

_quota_parse_help()
{
    local opts=$(_parse_help "$1")
    COMPREPLY=($(compgen -W '${opts:-$(_parse_usage "$1")}' -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
}

_quota_formats()
{
    COMPREPLY=($(compgen -W 'vfsold vfsv0 rpc xfs' -- "$cur"))
}

_filesystems()
{
    #  Only list filesystems starting with "/", otherwise we also get
    #+ "binfmt_misc", "proc", "tmpfs", ...
    COMPREPLY=($(compgen -W "$(awk '/^\// {print $1}' /etc/mtab)" \
        -- "$cur"))
}

_quota()
{
    local cur prev words cword split
    _init_completion -s || return

    case $prev in
        -F | --format)
            _quota_formats
            return
            ;;
        -h | --help | -V | --version)
            return
            ;;
    esac

    $split && return

    if [[ $cur == -* ]]; then
        _quota_parse_help "$1"
    else
        _user_or_group
    fi
} &&
    complete -F _quota -o default quota

_setquota()
{
    local cur prev words cword split
    _init_completion -s || return

    case $prev in
        -F | --format)
            _quota_formats
            return
            ;;
        -p | --prototype)
            _user_or_group
            return
            ;;
        -h | --help | -V | --version)
            return
            ;;
    esac

    $split && return

    if [[ $cur == -* ]]; then
        _quota_parse_help "$1"
    else
        local args
        _count_args

        case $args in
            1)
                _user_or_group
                ;;
            2)
                _filesystems
                ;;
        esac

    fi
} &&
    complete -F _setquota -o default setquota

_edquota()
{
    local cur prev words cword split
    _init_completion -s || return

    case $prev in
        -F | --format)
            _quota_formats
            return
            ;;
        -f | --filesystem)
            _filesystems
            return
            ;;
        -p | --prototype)
            _user_or_group
            return
            ;;
        -h | --help | -V | --version)
            return
            ;;
    esac

    $split && return

    if [[ $cur == -* ]]; then
        _quota_parse_help "$1"
    else
        _user_or_group
    fi
} &&
    complete -F _edquota -o default edquota

_quotacheck()
{
    local cur prev words cword split
    _init_completion -s || return

    case $prev in
        -F | --format)
            _quota_formats
            return
            ;;
        -h | --help | -V | --version)
            return
            ;;
    esac

    $split && return

    if [[ $cur == -* ]]; then
        _quota_parse_help "$1"
    else
        _filesystems
    fi
} &&
    complete -F _quotacheck -o default quotacheck repquota

_quotaon()
{
    local cur prev words cword split
    _init_completion -s || return

    case $prev in
        -F | --format)
            _quota_formats
            return
            ;;
        -x | --xfs-command)
            COMPREPLY=($(compgen -W 'delete enforce' -- "$cur"))
            return
            ;;
        -h | --help | -V | --version)
            return
            ;;
    esac

    $split && return

    if [[ $cur == -* ]]; then
        _quota_parse_help "$1"
    else
        _filesystems
    fi
} &&
    complete -F _quotaon -o default quotaon quotaoff

# ex: filetype=sh