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