/bash_completion_lib/complete/update-rc.d!

http://github.com/brinkman83/bashrc · Unknown · 71 lines · 60 code · 11 blank · 0 comment · 0 complexity · 4b43917c6e2af7bcb1bd37507c611945 MD5 · raw file

  1. # update-rc.d(8) completion
  2. #
  3. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  4. comp_include _get_cword
  5. _update_rc_d()
  6. {
  7. local cur prev sysvdir services options valid_options
  8. cur=`_get_cword`
  9. prev=${COMP_WORDS[COMP_CWORD-1]}
  10. [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  11. || sysvdir=/etc/init.d
  12. services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
  13. services=( ${services[@]#$sysvdir/} )
  14. options=( -f -n )
  15. if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
  16. valid_options=( $( \
  17. echo "${COMP_WORDS[@]} ${options[@]}" \
  18. | tr " " "\n" \
  19. | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
  20. | sort | uniq -u \
  21. ) )
  22. COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
  23. -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
  24. elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
  25. COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
  26. elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
  27. COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  28. elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
  29. COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  30. elif [[ "$prev" == defaults && -z "$cur" ]]; then
  31. COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
  32. elif [[ "$prev" == ?(start|stop) ]]; then
  33. if [[ "$cur" == [0-9] || -z "$cur" ]]; then
  34. COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  35. elif [[ "$cur" == [0-9][0-9] ]]; then
  36. COMPREPLY=( $cur )
  37. else
  38. COMPREPLY=()
  39. fi
  40. elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
  41. if [[ -z "$cur" ]]; then
  42. if [[ $prev == [0-9][0-9] ]]; then
  43. COMPREPLY=( 0 1 2 3 4 5 6 S )
  44. else
  45. COMPREPLY=( 0 1 2 3 4 5 6 S . )
  46. fi
  47. elif [[ "$cur" == [0-6S.] ]]; then
  48. COMPREPLY=( $cur )
  49. else
  50. COMPREPLY=()
  51. fi
  52. elif [[ "$prev" == "." ]]; then
  53. COMPREPLY=( $(compgen -W "start stop" -- $cur) )
  54. else
  55. COMPREPLY=()
  56. fi
  57. return 0
  58. } # _update_rc_d()
  59. comp_install -F _update_rc_d # Make completion persistent for subsequent invocations
  60. _update_rc_d # Generate completions for first invocation