/bash_completion.d/shadow

http://github.com/brinkman83/bashrc · #! · 501 lines · 406 code · 95 blank · 0 comment · 0 complexity · c62642a786329aa07702b0c09965a9e8 MD5 · raw file

  1. # bash completion for shadow utils
  2. have useradd &&
  3. _useradd()
  4. {
  5. local cur prev split=false
  6. COMPREPLY=()
  7. cur=`_get_cword`
  8. prev=${COMP_WORDS[COMP_CWORD-1]}
  9. _split_longopt && split=true
  10. # TODO: if -o/--non-unique is given, could complete on existing uids
  11. # with -u/--uid
  12. case "$prev" in
  13. -c|--comment|-h|--help|-e|--expiredate|-f|--inactive|-k|--key|-p|--password|-u|--uid|-Z|--selinux-user)
  14. return 0
  15. ;;
  16. -b|--base-dir|-d|--home|-k|--skel)
  17. _filedir -d
  18. return 0
  19. ;;
  20. -g|--gid)
  21. _gids
  22. [ -n "$bash205" ] && \
  23. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -g ) )
  24. COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
  25. return 0
  26. ;;
  27. -G|--groups)
  28. [ -n "$bash205" ] && \
  29. COMPREPLY=( $( compgen -g -- "$cur" ) )
  30. return 0
  31. ;;
  32. -s|--shell)
  33. _shells
  34. return 0
  35. ;;
  36. esac
  37. $split && return 0
  38. if [[ "$cur" == -* ]]; then
  39. COMPREPLY=( $( compgen -W '-b --base-dir -c --comment -d --home\
  40. -D --defaults -e --expiredate -f --inactive -g --gid \
  41. -G --groups -h --help -k --skel -K --key -l -M \
  42. -m --create-home -N --no-user-group -o --non-unique \
  43. -p --password -r --system -s --shell -u --uid \
  44. -U --user-group -Z --selinux-user' -- "$cur" ) )
  45. return 0
  46. fi
  47. } &&
  48. complete -F _useradd useradd
  49. have usermod &&
  50. _usermod()
  51. {
  52. local cur prev split=false
  53. COMPREPLY=()
  54. cur=`_get_cword`
  55. prev=${COMP_WORDS[COMP_CWORD-1]}
  56. _split_longopt && split=true
  57. # TODO: if -o/--non-unique is given, could complete on existing uids
  58. # with -u/--uid
  59. case "$prev" in
  60. -c|--comment|-d|--home|-e|--expiredate|-f|--inactive|-h|--help|-l|--login|-p|--password|-u|--uid|-Z|--selinux-user)
  61. return 0
  62. ;;
  63. -g|--gid)
  64. _gids
  65. [ -n "$bash205" ] && \
  66. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -g ) )
  67. COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
  68. return 0
  69. ;;
  70. -G|--groups)
  71. [ -n "$bash205" ] && \
  72. COMPREPLY=( $( compgen -g -- "$cur" ) )
  73. return 0
  74. ;;
  75. -s|--shell)
  76. _shells
  77. return 0
  78. ;;
  79. esac
  80. $split && return 0
  81. if [[ "$cur" == -* ]]; then
  82. # TODO: -U/--unlock, -p/--password, -L/--lock mutually exclusive
  83. COMPREPLY=( $( compgen -W '-a --append -c --comment -d --home \
  84. -e --expiredate -f --inactive -g --gid -G --groups \
  85. -h --help -l --login -L --lock -o --non-unique \
  86. -p --password -s --shell -u --uid -U --unlock \
  87. -Z --selinux-user' -- "$cur" ) )
  88. return 0
  89. fi
  90. COMPREPLY=( $( compgen -u -- "$cur" ) )
  91. } &&
  92. complete -F _usermod usermod
  93. have userdel &&
  94. _userdel()
  95. {
  96. local cur
  97. COMPREPLY=()
  98. cur=`_get_cword`
  99. if [[ "$cur" == -* ]]; then
  100. COMPREPLY=( $( compgen -W '-f --force -h --help -r --remove' \
  101. -- "$cur" ) )
  102. return 0
  103. fi
  104. COMPREPLY=( $( compgen -u -- "$cur" ) )
  105. } &&
  106. complete -F _userdel userdel
  107. have chage &&
  108. _chage()
  109. {
  110. local cur prev split=false
  111. COMPREPLY=()
  112. cur=`_get_cword`
  113. prev=${COMP_WORDS[COMP_CWORD-1]}
  114. _split_longopt && split=true
  115. case "$prev" in
  116. -d|--lastday|-E|--expiredate|-h|--help|-I|--inactive|-m|--mindays|-M|--maxdays|-W|--warndays)
  117. return 0
  118. ;;
  119. esac
  120. $split && return 0
  121. if [[ "$cur" == -* ]]; then
  122. COMPREPLY=( $( compgen -W '-d --lastday -E --expiredate \
  123. -h --help -I --inactive -l --list -m --mindays \
  124. -M --maxdays -W --warndays' -- "$cur" ) )
  125. return 0
  126. fi
  127. COMPREPLY=( $( compgen -u -- "$cur" ) )
  128. } &&
  129. complete -F _chage chage
  130. have passwd &&
  131. _passwd()
  132. {
  133. local cur prev
  134. COMPREPLY=()
  135. cur=`_get_cword`
  136. prev=${COMP_WORDS[COMP_CWORD-1]}
  137. case "$prev" in
  138. -n|-x|-w|-i|-\?|--help|--usage)
  139. return 0
  140. ;;
  141. esac
  142. if [[ "$cur" == -* ]]; then
  143. COMPREPLY=( $( compgen -W '-k -l --stdin -u -d -n -x -w -i -S \
  144. -? --help --usage' -- "$cur" ) )
  145. return 0
  146. fi
  147. COMPREPLY=( $( compgen -u -- "$cur" ) )
  148. } &&
  149. complete -F _passwd passwd
  150. have chpasswd &&
  151. _chpasswd()
  152. {
  153. local cur prev split=false
  154. COMPREPLY=()
  155. cur=`_get_cword`
  156. prev=${COMP_WORDS[COMP_CWORD-1]}
  157. _split_longopt && split=true
  158. case "$prev" in
  159. -c|--crypt)
  160. COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
  161. -- "$cur" ) )
  162. return 0
  163. ;;
  164. -s|--sha-rounds)
  165. return 0
  166. ;;
  167. esac
  168. $split && return 0
  169. if [[ "$cur" == -* ]]; then
  170. COMPREPLY=( $( compgen -W '-c --crypt-method -e --encrypted \
  171. -h --help -m --md5 -s --sha-rounds' -- "$cur" ) )
  172. return 0
  173. fi
  174. } &&
  175. complete -F _chpasswd chpasswd
  176. have newusers &&
  177. _newusers()
  178. {
  179. local cur prev split=false
  180. COMPREPLY=()
  181. cur=`_get_cword`
  182. prev=${COMP_WORDS[COMP_CWORD-1]}
  183. _split_longopt && split=true
  184. case "$prev" in
  185. -c|--crypt)
  186. COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
  187. -- "$cur" ) )
  188. return 0
  189. ;;
  190. -s|--sha-rounds)
  191. return 0
  192. ;;
  193. esac
  194. $split && return 0
  195. if [[ "$cur" == -* ]]; then
  196. COMPREPLY=( $( compgen -W '-c --crypt-method --r --system \
  197. -s --sha-rounds' -- "$cur" ) )
  198. return 0
  199. fi
  200. _filedir
  201. } &&
  202. complete -F _newusers $filenames newusers
  203. have pwck &&
  204. _pwck()
  205. {
  206. local cur
  207. COMPREPLY=()
  208. cur=`_get_cword`
  209. if [[ "$cur" == -* ]]; then
  210. COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) )
  211. return 0
  212. fi
  213. _filedir
  214. } &&
  215. complete -F _pwck $filenames pwck
  216. have groupadd &&
  217. _groupadd()
  218. {
  219. local cur prev split=false
  220. COMPREPLY=()
  221. cur=`_get_cword`
  222. prev=${COMP_WORDS[COMP_CWORD-1]}
  223. _split_longopt && split=true
  224. # TODO: if -o/--non-unique is given, could complete on existing gids
  225. # with -g/--gid
  226. case "$prev" in
  227. -g|--gid|-K|--key|-p|--password)
  228. return 0
  229. ;;
  230. esac
  231. $split && return 0
  232. if [[ "$cur" == -* ]]; then
  233. COMPREPLY=( $( compgen -W '-f --force -g --gid -h --help \
  234. -K --key -o --non-unique -p --password -r --system' \
  235. -- "$cur" ) )
  236. return 0
  237. fi
  238. } &&
  239. complete -F _groupadd groupadd
  240. have groupmod &&
  241. _groupmod()
  242. {
  243. local cur prev split=false
  244. COMPREPLY=()
  245. cur=`_get_cword`
  246. prev=${COMP_WORDS[COMP_CWORD-1]}
  247. _split_longopt && split=true
  248. # TODO: if -o/--non-unique is given, could complete on existing gids
  249. # with -g/--gid
  250. case "$prev" in
  251. -g|--gid|-h|--help|-n|--new-name|-p|--password)
  252. return 0
  253. ;;
  254. esac
  255. $split && return 0
  256. if [[ "$cur" == -* ]]; then
  257. COMPREPLY=( $( compgen -W '-g --gid -h --help -n --new-name \
  258. -o --non-unique -p --password' -- "$cur" ) )
  259. return 0
  260. fi
  261. [ -n "$bash205" ] && COMPREPLY=( $( compgen -g -- "$cur" ) )
  262. } &&
  263. complete -F _groupmod groupmod
  264. [ -n "$bash205" ] && complete -g groupdel
  265. have newgrp &&
  266. _newgrp()
  267. {
  268. COMPREPLY=()
  269. if [[ "`_get_cword`" == "-" ]]; then
  270. COMPREPLY=( - )
  271. fi
  272. } &&
  273. complete ${bash205:+-g} -F _newgrp newgrp
  274. have gpasswd &&
  275. _gpasswd()
  276. {
  277. local cur prev
  278. COMPREPLY=()
  279. cur=`_get_cword`
  280. prev=${COMP_WORDS[COMP_CWORD-1]}
  281. case "$prev" in
  282. -a|-d|-A|-M)
  283. COMPREPLY=( $( compgen -u -- "$cur" ) )
  284. return 0
  285. ;;
  286. esac
  287. if [[ "$cur" == -* ]]; then
  288. COMPREPLY=( $( compgen -W '-a -d -r -R -A -M' -- "$cur" ) )
  289. return 0
  290. fi
  291. [ -n "$bash205" ] && COMPREPLY=( $( compgen -g -- "$cur" ) )
  292. } &&
  293. complete -F _gpasswd gpasswd
  294. have groupmems &&
  295. _groupmems()
  296. {
  297. local cur prev
  298. COMPREPLY=()
  299. cur=`_get_cword`
  300. prev=${COMP_WORDS[COMP_CWORD-1]}
  301. case "$prev" in
  302. -a|-d)
  303. COMPREPLY=( $( compgen -u -- "$cur" ) )
  304. return 0
  305. ;;
  306. -g)
  307. [ -n "$bash205" ] && \
  308. COMPREPLY=( $( compgen -g -- "$cur" ) )
  309. return 0
  310. ;;
  311. esac
  312. if [[ "$cur" == -* ]]; then
  313. COMPREPLY=( $( compgen -W '-a -d -p -g -l' -- "$cur" ) )
  314. return 0
  315. fi
  316. } &&
  317. complete -F _groupmems groupmems
  318. have grpck &&
  319. _grpck()
  320. {
  321. local cur
  322. COMPREPLY=()
  323. cur=`_get_cword`
  324. if [[ "$cur" == -* ]]; then
  325. COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) )
  326. return 0
  327. fi
  328. _filedir
  329. } &&
  330. complete -F _grpck $filenames grpck
  331. have vipw || have vigr &&
  332. _vipw()
  333. {
  334. local cur prev
  335. COMPREPLY=()
  336. cur=`_get_cword`
  337. prev=${COMP_WORDS[COMP_CWORD-1]}
  338. case "$prev" in
  339. -h|--help)
  340. return 0
  341. ;;
  342. esac
  343. if [[ "$cur" == -* ]]; then
  344. COMPREPLY=( $( compgen -W '-g --group -h --help -p --passwd \
  345. -q --quiet -s --shadow' -- "$cur" ) )
  346. return 0
  347. fi
  348. } &&
  349. complete -F _vipw vipw vigr
  350. have faillog &&
  351. _faillog()
  352. {
  353. local cur prev split=false
  354. COMPREPLY=()
  355. cur=`_get_cword`
  356. prev=${COMP_WORDS[COMP_CWORD-1]}
  357. _split_longopt && split=true
  358. case "$prev" in
  359. -h|--help|-l|--lock-time|-m|--maximum|-t|--time)
  360. return 0
  361. ;;
  362. -u|--user)
  363. COMPREPLY=( $( compgen -u -- "$cur" ) )
  364. return 0
  365. ;;
  366. esac
  367. $split && return 0
  368. if [[ "$cur" == -* ]]; then
  369. COMPREPLY=( $( compgen -W '-a --all -h --help -l --lock-time \
  370. -m --maximum -r --reset -t --time -u --user' -- "$cur" ) )
  371. return 0
  372. fi
  373. } &&
  374. complete -F _faillog faillog
  375. have lastlog &&
  376. _lastlog()
  377. {
  378. local cur prev split=false
  379. COMPREPLY=()
  380. cur=`_get_cword`
  381. prev=${COMP_WORDS[COMP_CWORD-1]}
  382. _split_longopt && split=true
  383. case "$prev" in
  384. -b|--before|-h|--help|-t|--time)
  385. return 0
  386. ;;
  387. -u|--user)
  388. COMPREPLY=( $( compgen -u -- "$cur" ) )
  389. return 0
  390. ;;
  391. esac
  392. $split && return 0
  393. if [[ "$cur" == -* ]]; then
  394. COMPREPLY=( $( compgen -W '-b --before -h --help -t --time \
  395. -u --user' -- "$cur" ) )
  396. return 0
  397. fi
  398. } &&
  399. complete -F _lastlog lastlog
  400. # Local variables:
  401. # mode: shell-script
  402. # sh-basic-offset: 4
  403. # sh-indent-comment: t
  404. # indent-tabs-mode: nil
  405. # End:
  406. # ex: ts=4 sw=4 et filetype=sh