my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.7 KiB

3 years ago
  1. #!/bin/zsh -f
  2. #compdef pm2
  3. #autoload
  4. local -a _1st_arguments
  5. _1st_arguments=(
  6. "start:start and daemonize an app"
  7. "trigger:trigger process action"
  8. "deploy:deploy your json"
  9. "startOrRestart:start or restart JSON file"
  10. "startOrReload:start or gracefully reload JSON file"
  11. "pid:return pid of [app_name] or all"
  12. "stop:stop a process"
  13. "restart:restart a process"
  14. "scale:scale up/down a process in cluster mode depending on total_number param"
  15. "profile\:mem:Sample PM2 heap memory"
  16. "profile\:cpu:Profile PM2 cpu"
  17. "reload:reload processes (note that its for app using HTTP/HTTPS)"
  18. "id:get process id by name"
  19. "inspect:inspect a process"
  20. "delete:stop and delete a process from pm2 process list"
  21. "sendSignal:send a system signal to the target process"
  22. "ping:ping pm2 daemon - if not up it will launch it"
  23. "updatePM2:update in-memory PM2 with local PM2"
  24. "install:install or update a module and run it forever"
  25. "module\:update:update a module and run it forever"
  26. "module\:generate:Generate a sample module in current folder"
  27. "uninstall:stop and uninstall a module"
  28. "package:Check & Package TAR type module"
  29. "publish:Publish the module you are currently on"
  30. "set:sets the specified config <key> <value>"
  31. "multiset:multiset eg \"key1 val1 key2 val2\""
  32. "get:get value for <key>"
  33. "config:get / set module config values"
  34. "unset:clears the specified config <key>"
  35. "report:give a full pm2 report for https\://github.com/Unitech/pm2/issues"
  36. "link:link with the pm2 monitoring dashboard"
  37. "unlink:unlink with the pm2 monitoring dashboard"
  38. "monitor:monitor target process"
  39. "unmonitor:unmonitor target process"
  40. "open:open the pm2 monitoring dashboard"
  41. "plus:enable pm2 plus"
  42. "login:Login to pm2 plus"
  43. "logout:Logout from pm2 plus"
  44. "web:launch a health API on 0.0.0.0\:9615"
  45. "dump:dump all processes for resurrecting them later"
  46. "cleardump:Create empty dump file"
  47. "send:send stdin to <pm_id>"
  48. "attach:attach stdin/stdout to application identified by <pm_id>"
  49. "resurrect:resurrect previously dumped processes"
  50. "unstartup:disable the pm2 startup hook"
  51. "startup:enable the pm2 startup hook"
  52. "logrotate:copy default logrotate configuration"
  53. "ecosystem:generate a process conf file. (mode = null or simple)"
  54. "reset:reset counters for process"
  55. "describe:describe all parameters of a process id"
  56. "list:list all processes"
  57. "jlist:list all processes in JSON format"
  58. "prettylist:print json in a prettified JSON"
  59. "monit:launch termcaps monitoring"
  60. "imonit:launch legacy termcaps monitoring"
  61. "dashboard:launch dashboard with monitoring and logs"
  62. "flush:flush logs"
  63. "reloadLogs:reload all logs"
  64. "logs:stream logs file. Default stream all logs"
  65. "kill:kill daemon"
  66. "pull:updates repository for a given app"
  67. "forward:updates repository to the next commit for a given app"
  68. "backward:downgrades repository to the previous commit for a given app"
  69. "deepUpdate:performs a deep update of PM2"
  70. "serve:serve a directory over http via port"
  71. "examples:display pm2 usage examples"
  72. )
  73. local -a id_names
  74. _id_names() {
  75. local app_list
  76. app_list=`pm2 list -m`
  77. local -a names ids
  78. names=(`echo $app_list | grep '+---' | awk '{print $2}'`)
  79. ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`)
  80. if (( ${#ids} > 0 )); then
  81. for i in {1..${#ids}}; do
  82. id_names+=( "${ids[i]}:${names[i]}" )
  83. done
  84. fi
  85. }
  86. _arguments \
  87. '(-v --version)'{-v,--version}'[output version]' \
  88. '(-h --help)'{-h,--help}'[output usage information]' \
  89. '*:: :->subcmds' && return 0
  90. if (( CURRENT == 1 )); then
  91. _describe "command" _1st_arguments
  92. return
  93. fi
  94. local -a id_comp id_all_comp id_all_files_comp start_options logs_options
  95. id_comp=('1: :->id_comp')
  96. id_all_comp=('1: :->id_all_comp')
  97. id_all_files_comp=('1: :->id_all_files_comp')
  98. start_options=(
  99. '--watch[Watch folder for changes]'
  100. '--fresh[Rebuild Dockerfile]'
  101. '--daemon[Run container in Daemon mode (debug purposes)]'
  102. '--container[Start application in container mode]'
  103. '--dist[with --container; change local Dockerfile to containerize all files in current directory]'
  104. '--image-name[with --dist; set the exported image name]'
  105. '--node-version[with --container, set a specific major Node.js version]'
  106. '--dockerdaemon[for debugging purpose]'
  107. '(-h --help)'{-h,--help}'[output usage information]'
  108. $id_all_files_comp
  109. )
  110. logs_options=(
  111. '--json[json log output]'
  112. '--format[formated log output]'
  113. '--raw[raw output]'
  114. '--err[only shows error output]'
  115. '--out[only shows standard output]'
  116. '--lines[output the last N lines, instead of the last 15 by default]'
  117. '--timestamp[add timestamps (default format YYYY-MM-DD-HH:mm:ss)]'
  118. '--nostream[print logs without launching the log stream]'
  119. '(-h --help)'{-h,--help}'[output usage information]'
  120. $id_all_comp
  121. )
  122. case "$words[1]" in
  123. start)
  124. _arguments $start_options && return 0
  125. ;;
  126. logs)
  127. _arguments $logs_options && return 0
  128. ;;
  129. stop|restart|delete|reload|reset)
  130. _arguments $id_all_comp && return 0
  131. ;;
  132. env|inspect|monitor|unmonitor|describe)
  133. _arguments $id_comp && return 0
  134. ;;
  135. deploy|startOrRestart|startOrReload)
  136. _files ;;
  137. esac
  138. case "$state" in
  139. id_comp)
  140. _id_names
  141. _alternative \
  142. 'args:app args:(($id_names))'
  143. ;;
  144. id_all_comp)
  145. _id_names
  146. id_names+=(all)
  147. _alternative \
  148. 'args:app args:(($id_names))'
  149. ;;
  150. id_all_files_comp)
  151. _id_names
  152. id_names+=(all)
  153. _alternative \
  154. 'args:app args:(($id_names))' \
  155. 'files:filename:_files'
  156. ;;
  157. esac