PageRenderTime 98ms CodeModel.GetById 93ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/quota-tools

http://github.com/brinkman83/bashrc
#! | 264 lines | 214 code | 50 blank | 0 comment | 0 complexity | 1d2534636563698a5cff2bc310f1a4b0 MD5 | raw file
  1# bash completion for quota-tools
  2
  3have quota && {
  4_user_or_group()
  5{
  6    local i
  7
  8    # complete on groups if -g was given
  9    for (( i=1; i < COMP_CWORD; i++ )); do
 10        if [[ "${COMP_WORDS[i]}" == -g ]]; then
 11            COMPREPLY=( $( compgen -g -- "$cur" ) )
 12            return 0
 13        fi
 14    done
 15
 16    # otherwise complete on users
 17    COMPREPLY=( $( compgen -u -- "$cur" ) )
 18}
 19
 20_quota_formats()
 21{
 22    COMPREPLY=( $( compgen -W 'vfsold vfsv0 rpc xfs' -- "$cur" ) )
 23}
 24
 25_filesystems()
 26{
 27    #  Only list filesystems starting with "/", otherwise we also get
 28    #+ "binfmt_misc", "proc", "tmpfs", ...
 29    COMPREPLY=( $( compgen -W "$(awk '/^\// {print $1}' /etc/mtab)" \
 30        -- "$cur" ) )
 31}
 32
 33_quota()
 34{
 35    local cur prev split=false
 36
 37    COMPREPLY=()
 38    cur=`_get_cword`
 39    prev=${COMP_WORDS[COMP_CWORD-1]}
 40
 41    _split_longopt && split=true
 42
 43    case $prev in
 44        -F|--format)
 45            _quota_formats
 46            return 0
 47            ;;
 48    esac
 49
 50    $split && return 0
 51
 52    if [[ "$cur" == -* ]]; then
 53        COMPREPLY=( $( compgen -W '-F --format -g --group -u --user -v \
 54            --verbose -s --human-readable -p --raw-grace -i --no-autofs -l \
 55            --local-only -A --all-nfs -m --no-mixed-pathnames -q --quiet -Q \
 56            --quiet-refuse -w --no-wrap' -- "$cur" ) )
 57    else
 58        _user_or_group
 59    fi
 60}
 61complete -F _quota $default quota
 62
 63_setquota()
 64{
 65    local cur prev split=false
 66
 67    COMPREPLY=()
 68    cur=`_get_cword`
 69    prev=${COMP_WORDS[COMP_CWORD-1]}
 70
 71    _split_longopt && split=true
 72
 73    case $prev in
 74        -F|--format)
 75            _quota_formats
 76            return 0
 77            ;;
 78    esac
 79
 80    $split && return 0
 81
 82    if [[ "$cur" == -* ]]; then
 83        COMPREPLY=( $( compgen -W '-r --remote -m --no-mixed-pathnames \
 84            -F --format -g --group -u --user -p --prototype -b --batch \
 85            -c --continue-batch -t --edit-period -T --edit-times -a --all' \
 86            -- "$cur" ) )
 87    else
 88        _count_args
 89
 90        case $args in
 91            1)
 92                _user_or_group
 93                ;;
 94            2)
 95                _filesystems
 96                ;;
 97        esac
 98
 99    fi
100}
101complete -F _setquota $default setquota
102
103_edquota()
104{
105    local cur prev split=false
106
107    COMPREPLY=()
108    cur=`_get_cword`
109    prev=${COMP_WORDS[COMP_CWORD-1]}
110
111    _split_longopt && split=true
112
113    case $prev in
114        -F|--format)
115            _quota_formats
116            return 0
117            ;;
118        -@(f|-filesystem))
119            _filesystems
120            return 0
121            ;;
122    esac
123
124    $split && return 0
125
126    if [[ "$cur" == -* ]]; then
127        COMPREPLY=( $( compgen -W '-r --remote -m --no-mixed-pathnames \
128            -g --group -u --user -p --prototype -F --format -f --filesystem \
129            -t --edit-period -T --edit-times' -- "$cur" ) )
130    else
131        _user_or_group
132    fi
133}
134complete -F _edquota $default edquota
135
136_quotacheck()
137{
138    local cur prev split=false
139
140    COMPREPLY=()
141    cur=`_get_cword`
142    prev=${COMP_WORDS[COMP_CWORD-1]}
143
144    _split_longopt && split=true
145
146    case $prev in
147        -F|--format)
148            _quota_formats
149            return 0
150            ;;
151    esac
152
153    $split && return 0
154
155    if [[ "$cur" == -* ]]; then
156        COMPREPLY=( $( compgen -W '-b --backup -v --verbose -d --debug \
157            -g --group -u --user -c --create-files -f --force -i \
158            --interactive -n --use-first-dquot -M --try-remount -m \
159            --no-remount -R --exclude-root -F --format -a --all' -- "$cur" ) )
160    else
161        _filesystems
162    fi
163}
164complete -F _quotacheck $default quotacheck
165
166_repquota()
167{
168    local cur prev split=false
169
170    COMPREPLY=()
171    cur=`_get_cword`
172    prev=${COMP_WORDS[COMP_CWORD-1]}
173
174    _split_longopt && split=true
175
176    case $prev in
177        -F|--format)
178            _quota_formats
179            return 0
180            ;;
181    esac
182
183    $split && return 0
184
185    if [[ "$cur" == -* ]]; then
186        COMPREPLY=( $( compgen -W '-a --all -v --verbose -s --human-readable \
187            -c --batch-translation -C --no-batch-translation -t \
188            --truncate-names -n --no-names -p --raw-grace -i --no-autofs \
189            -u --user -g --group -F --format' -- "$cur" ) )
190    else
191        _filesystems
192    fi
193}
194complete -F _repquota $default repquota
195
196_quotaon()
197{
198    local cur prev split=false
199
200    COMPREPLY=()
201    cur=`_get_cword`
202    prev=${COMP_WORDS[COMP_CWORD-1]}
203
204    _split_longopt && split=true
205
206    case $prev in
207        -F|--format)
208            _quota_formats
209            return 0
210            ;;
211    esac
212
213    $split && return 0
214
215    if [[ "$cur" == -* ]]; then
216        COMPREPLY=( $( compgen -W '-a --all -v --verbose -u --user \
217            -g --group -f --off -p --print-state -F --format' -- "$cur" ) )
218    else
219        _filesystems
220    fi
221}
222complete -F _quotaon $default quotaon
223
224_quotaoff()
225{
226    local cur prev split=false
227
228    COMPREPLY=()
229    cur=`_get_cword`
230    prev=${COMP_WORDS[COMP_CWORD-1]}
231
232    _split_longopt && split=true
233
234    case $prev in
235        -F|--format)
236            _quota_formats
237            return 0
238            ;;
239        -@(x|-xfs-command))
240            COMPREPLY=( $( compgen -W 'delete enforce' -- "$cur" ) )
241            return 0
242            ;;
243    esac
244
245    $split && return 0
246
247    if [[ "$cur" == -* ]]; then
248        COMPREPLY=( $( compgen -W '-a --all -v --verbose -u --user \
249            -g --group -p --print-state -x --xfs-command -F --format' \
250            -- "$cur" ) )
251    else
252        _filesystems
253    fi
254}
255complete -F _quotaoff $default quotaoff
256}
257
258# Local variables:
259# mode: shell-script
260# sh-basic-offset: 4
261# sh-indent-comment: t
262# indent-tabs-mode: nil
263# End:
264# ex: ts=4 sw=4 et filetype=sh