# bash completion for quota-tools -*- shell-script -*- proc _user_or_group { var 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 0 fi done # otherwise complete on users setglobal COMPREPLY = '( '$( compgen -u -- "$cur" ) ) } proc _quota_parse_help { var opts = $[ _parse_help $1] [[ $opts ]] || set opts = $[ _parse_usage $1] # non-GNU? setglobal COMPREPLY = '( '$( compgen -W "$opts" -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace } proc _quota_formats { setglobal COMPREPLY = '( '$( compgen -W 'vfsold vfsv0 rpc xfs' -- "$cur" ) ) } proc _filesystems { # Only list filesystems starting with "/", otherwise we also get #+ "binfmt_misc", "proc", "tmpfs", ... setglobal COMPREPLY = '( '$( compgen -W "$(awk '/^\// {print $1}' /etc/mtab)" \ -- "$cur" ) ) } proc _quota { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -F|--format _quota_formats return 0 with -h|--help|-V|--version return 0 } $split && return 0 if [[ "$cur" == -* ]] { _quota_parse_help $1 } else { _user_or_group } } && complete -F _quota -o default quota proc _setquota { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -F|--format _quota_formats return 0 with -p|--prototype _user_or_group return 0 with -h|--help|-V|--version return 0 } $split && return 0 if [[ "$cur" == -* ]] { _quota_parse_help $1 } else { var args = '' _count_args match $args { with 1 _user_or_group with 2 _filesystems } } } && complete -F _setquota -o default setquota proc _edquota { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -F|--format _quota_formats return 0 with -f|--filesystem _filesystems return 0 with -p|--prototype _user_or_group return 0 with -h|--help|-V|--version return 0 } $split && return 0 if [[ "$cur" == -* ]] { _quota_parse_help $1 } else { _user_or_group } } && complete -F _edquota -o default edquota proc _quotacheck { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -F|--format _quota_formats return 0 with -h|--help|-V|--version return 0 } $split && return 0 if [[ "$cur" == -* ]] { _quota_parse_help $1 } else { _filesystems } } && complete -F _quotacheck -o default quotacheck repquota proc _quotaon { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -F|--format _quota_formats return 0 with -x|--xfs-command setglobal COMPREPLY = '( '$( compgen -W 'delete enforce' -- "$cur" ) ) return 0 with -h|--help|-V|--version return 0 } $split && return 0 if [[ "$cur" == -* ]] { _quota_parse_help $1 } else { _filesystems } } && complete -F _quotaon -o default quotaon quotaoff # ex: ts=4 sw=4 et filetype=sh