_dinit 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #compdef dinitctl
  2. local current_context="$current_context" current_command
  3. local -a state commands arguments global_options command_options data home
  4. zstyle ':completion:*:sudo:*' environ SRV_HOME="/etc/dinit.d"
  5. home="$SRV_HOME/"
  6. commands=(
  7. 'status:datalay service status'
  8. 'start:start service (if not running yet)'
  9. 'restart:restart service (if already running)'
  10. 'stop:stop service'
  11. 'wake'
  12. 'release'
  13. 'unpin'
  14. 'unload'
  15. 'reload:reload service descriptor'
  16. 'list:list all loaded services'
  17. 'shutdown'
  18. 'add-dep'
  19. 'rm-dep'
  20. 'enable:enable service'
  21. 'disable:disable service'
  22. 'setenv'
  23. )
  24. global_options=(
  25. '--help:show help'
  26. '-s:control system daemon (default if run as root)]'
  27. '--system:control system daemon (default if run as root)]'
  28. '-u:control user daemon'
  29. '--user:control user daemon'
  30. '--quiet:suppress output (except errors)'
  31. '--socket-path:specify socket for communication with daemon]'
  32. '-p:specify socket for communication with daemon]'
  33. )
  34. arguments=()
  35. command_options=()
  36. if (( CURRENT == 2 )); then
  37. _describe -t 'commands' 'command' commands
  38. fi
  39. current_command=${words[2]#--}
  40. current_context="${current_context%:*}-$current_command:"
  41. case $current_command in
  42. status|enable|disable|unload|reload|unpin)
  43. arguments+='1:service:->services'
  44. ;;
  45. start|restart|stop|wake|release)
  46. arguments+='1:service:->services'
  47. command_options+=(
  48. '--no-wait:dont wait for service startup/shutdown to complete'
  49. '--pin:pin the service in the requested state'
  50. '--force:force stop even if dependents will be affected'
  51. )
  52. ;;
  53. *)
  54. :
  55. ;;
  56. esac
  57. shift words
  58. (( CURRENT-- ))
  59. _arguments -C -A "-*" $arguments
  60. case $state in
  61. services)
  62. data=( $(find "$home" -type f -printf '%P\n') )
  63. _describe -t 'services' 'service' data
  64. ret=0
  65. ;;
  66. *)
  67. ret=0
  68. ;;
  69. esac
  70. if [[ -prefix - ]]; then
  71. _describe -t 'global options' 'global option' global_options
  72. _describe -t 'command options' 'command option' command_options
  73. ret=0
  74. fi
  75. return $ret