dinitctl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. if [ -d /etc/dinit.d/ ]; then
  3. _etc_dinit_services_path="/etc/dinit.d/"
  4. else
  5. _etc_dinit_services_path=""
  6. fi
  7. if [ -d /lib/dinit.d/ ]; then
  8. _lib_dinit_services_path="/lib/dinit.d/"
  9. else
  10. _lib_dinit_services_path=""
  11. fi
  12. if [ -d /usr/local/lib/dinit.d/ ]; then
  13. _usr_dinit_services_path="/usr/local/lib/dinit.d/"
  14. else
  15. _usr_dinit_services_path=""
  16. fi
  17. if [ -d $HOME/.config/dinit.d/ ]; then
  18. _dinit_user_services_path="$HOME/.config/dinit.d/"
  19. else
  20. _dinit_user_services_path=""
  21. fi
  22. _dinit_all_services() {
  23. for path in $_etc_dinit_services_path $_usr_dinit_services_path\
  24. $_lib_dinit_services_path $_dinit_user_services_path; do
  25. ls $path
  26. done
  27. }
  28. _dinitctl_comp() {
  29. local cur=${COMP_WORDS[COMP_CWORD]}
  30. local thr=1
  31. local flags=()
  32. for word in "${COMP_WORDS[@]}"; do
  33. if [[ $word == -* || $word == --* ]]; then
  34. flags+=("$word")
  35. fi
  36. done
  37. ((thr+=${#flags[@]}))
  38. if [ ${COMP_CWORD} -gt $(($thr + 2)) ]; then
  39. return
  40. fi
  41. if [ ${COMP_CWORD} -eq $thr ]; then
  42. COMPREPLY=($(compgen -W\
  43. "status\
  44. list\
  45. start\
  46. stop\
  47. restart\
  48. enable\
  49. disable\
  50. is-started\
  51. is-failed\
  52. wake\
  53. release\
  54. unpin\
  55. unload\
  56. reload\
  57. shutdown\
  58. add-dep\
  59. rm-dep\
  60. trigger\
  61. untrigger\
  62. setenv\
  63. catlog\
  64. signal\
  65. " -- "$cur"))
  66. return
  67. fi
  68. local services
  69. case "${COMP_WORDS[$thr]}" in
  70. "start"|"stop"|"restart"|"status"|"disable"|"enable"|"is-started"|"is-failed"|\
  71. "add-dep"|"rm-dep"|"trigger"|"untrigger"|"wake"|"release"|"unpin"|"unload"|\
  72. "reload"|"catlog"|"signal")
  73. services=$(_dinit_all_services)
  74. esac
  75. if [ -z "$services" ]; then
  76. return
  77. fi
  78. COMPREPLY=($(compgen -W "$services" -- "$cur"))
  79. }
  80. complete -F _dinitctl_comp dinitctl