/bash_completion.d/getent

http://github.com/brinkman83/bashrc · #! · 56 lines · 50 code · 6 blank · 0 comment · 0 complexity · d394036ecf826719368728ddc6f53cbc MD5 · raw file

  1. # bash completion for getent
  2. have getent &&
  3. _getent()
  4. {
  5. local cur prev
  6. COMPREPLY=()
  7. cur=`_get_cword`
  8. prev=${COMP_WORDS[COMP_CWORD-1]}
  9. case $prev in
  10. passwd)
  11. COMPREPLY=( $( compgen -u "$cur" ) )
  12. return 0
  13. ;;
  14. group)
  15. COMPREPLY=( $( compgen -g "$cur" ) )
  16. return 0
  17. ;;
  18. services)
  19. COMPREPLY=( $( compgen -s "$cur" ) )
  20. return 0
  21. ;;
  22. hosts)
  23. COMPREPLY=( $( compgen -A hostname "$cur" ) )
  24. return 0
  25. ;;
  26. protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)
  27. COMPREPLY=( $( compgen -W "$( getent "$prev" | \
  28. awk '{ print $1 }' )" -- "$cur" ) )
  29. return 0
  30. ;;
  31. aliases|shadow)
  32. COMPREPLY=( $( compgen -W "$( getent "$prev" | cut -d: -f1 )" \
  33. -- "$cur" ) )
  34. return 0
  35. ;;
  36. esac
  37. if [ $COMP_CWORD -eq 1 ]; then
  38. COMPREPLY=( $( compgen -W 'passwd group hosts services protocols \
  39. networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc \
  40. shadow' -- "$cur" ) )
  41. fi
  42. } &&
  43. complete -F _getent getent
  44. # Local variables:
  45. # mode: shell-script
  46. # sh-basic-offset: 4
  47. # sh-indent-comment: t
  48. # indent-tabs-mode: nil
  49. # End:
  50. # ex: ts=4 sw=4 et filetype=sh