herd 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. _herd_complete_subcommand()
  2. {
  3. local command="${COMP_WORDS[1]}"
  4. case "$command" in
  5. discover)
  6. complitions="guix-daemon"
  7. COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}"))
  8. ;;
  9. schedule)
  10. complitions="mcron"
  11. COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}"))
  12. ;;
  13. set-http-proxy)
  14. complitions="guix-daemon"
  15. COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}"))
  16. ;;
  17. *)
  18. local services="$(herd status | grep '^ +\|^ -\| \*' | cut -d ' ' -f3)"
  19. COMPREPLY=($(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}"))
  20. ;;
  21. esac
  22. }
  23. _herd_complete_3()
  24. {
  25. local command="${COMP_WORDS[2]}"
  26. case "$command" in
  27. guix-daemon)
  28. complitions="on off"
  29. COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}"))
  30. ;;
  31. *)
  32. ;;
  33. esac
  34. }
  35. _herd_is_command ()
  36. {
  37. local word
  38. local result="false"
  39. for word in ${COMP_WORDS[*]}
  40. do
  41. if [ "$word" = "$1" ]
  42. then
  43. result=true
  44. break
  45. fi
  46. done
  47. $result
  48. }
  49. _herd_complete()
  50. {
  51. local word_count=${#COMP_WORDS[*]}
  52. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  53. case $COMP_CWORD in
  54. 1)
  55. if [ -z "$_herd_subcommands" ]
  56. then
  57. # Cache the list of subcommands to speed things up.
  58. _herd_subcommands=(
  59. disable
  60. discover
  61. enable
  62. schedule
  63. set-http-proxy
  64. start
  65. status
  66. stop
  67. )
  68. _herd_subcommands="${_herd_subcommands[@]}"
  69. fi
  70. COMPREPLY=($(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
  71. ;;
  72. *)
  73. case $COMP_CWORD in
  74. 2) _herd_complete_subcommand;;
  75. 3) _herd_complete_3;;
  76. esac
  77. ;;
  78. esac
  79. }
  80. complete -F _herd_complete herd