summaryrefslogtreecommitdiff
path: root/plugins/pm2
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-07-11 19:58:51 -0600
committerTuowen Zhao <ztuowen@gmail.com>2021-07-11 19:58:51 -0600
commit617ed3bd9f3d9519fe2354941f3dbf15b0c712ee (patch)
treecaf617b35d3f5f7b5786483eedfcda9361dca108 /plugins/pm2
parent0144641b7d8e4e6ff6ce153039b5a827f5347904 (diff)
parent36f444ed7325720ec05f182781ec7d6c9a4d675c (diff)
downloadzsh-617ed3bd9f3d9519fe2354941f3dbf15b0c712ee.tar.gz
zsh-617ed3bd9f3d9519fe2354941f3dbf15b0c712ee.tar.bz2
zsh-617ed3bd9f3d9519fe2354941f3dbf15b0c712ee.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/pm2')
-rw-r--r--plugins/pm2/README.md19
-rw-r--r--plugins/pm2/_pm2168
-rw-r--r--plugins/pm2/pm2.plugin.zsh6
3 files changed, 193 insertions, 0 deletions
diff --git a/plugins/pm2/README.md b/plugins/pm2/README.md
new file mode 100644
index 000000000..5dfd540b6
--- /dev/null
+++ b/plugins/pm2/README.md
@@ -0,0 +1,19 @@
+# pm2 plugin
+
+The plugin adds several aliases and completions for common [pm2](http://pm2.keymetrics.io/) commands.
+
+To use it, add `pm2` to the plugins array of your zshrc file:
+```
+plugins=(... pm2)
+```
+
+## Aliases
+
+| Alias | Command |
+|--------|----------------------|
+| p2s | `pm2 start` |
+| p2o | `pm2 stop` |
+| p2d | `pm2 delete` |
+| p2r | `pm2 restart` |
+| p2i | `pm2 list` |
+| p2l | `pm2 logs` |
diff --git a/plugins/pm2/_pm2 b/plugins/pm2/_pm2
new file mode 100644
index 000000000..6f1e89df5
--- /dev/null
+++ b/plugins/pm2/_pm2
@@ -0,0 +1,168 @@
+#!/bin/zsh -f
+#compdef pm2
+#autoload
+
+local -a _1st_arguments
+
+_1st_arguments=(
+ "start:start and daemonize an app"
+ "trigger:trigger process action"
+ "deploy:deploy your json"
+ "startOrRestart:start or restart JSON file"
+ "startOrReload:start or gracefully reload JSON file"
+ "pid:return pid of [app_name] or all"
+ "stop:stop a process"
+ "restart:restart a process"
+ "scale:scale up/down a process in cluster mode depending on total_number param"
+ "profile\:mem:Sample PM2 heap memory"
+ "profile\:cpu:Profile PM2 cpu"
+ "reload:reload processes (note that its for app using HTTP/HTTPS)"
+ "id:get process id by name"
+ "inspect:inspect a process"
+ "delete:stop and delete a process from pm2 process list"
+ "sendSignal:send a system signal to the target process"
+ "ping:ping pm2 daemon - if not up it will launch it"
+ "updatePM2:update in-memory PM2 with local PM2"
+ "install:install or update a module and run it forever"
+ "module\:update:update a module and run it forever"
+ "module\:generate:Generate a sample module in current folder"
+ "uninstall:stop and uninstall a module"
+ "package:Check & Package TAR type module"
+ "publish:Publish the module you are currently on"
+ "set:sets the specified config <key> <value>"
+ "multiset:multiset eg \"key1 val1 key2 val2\""
+ "get:get value for <key>"
+ "config:get / set module config values"
+ "unset:clears the specified config <key>"
+ "report:give a full pm2 report for https\://github.com/Unitech/pm2/issues"
+ "link:link with the pm2 monitoring dashboard"
+ "unlink:unlink with the pm2 monitoring dashboard"
+ "monitor:monitor target process"
+ "unmonitor:unmonitor target process"
+ "open:open the pm2 monitoring dashboard"
+ "plus:enable pm2 plus"
+ "login:Login to pm2 plus"
+ "logout:Logout from pm2 plus"
+ "web:launch a health API on 0.0.0.0\:9615"
+ "dump:dump all processes for resurrecting them later"
+ "cleardump:Create empty dump file"
+ "send:send stdin to <pm_id>"
+ "attach:attach stdin/stdout to application identified by <pm_id>"
+ "resurrect:resurrect previously dumped processes"
+ "unstartup:disable the pm2 startup hook"
+ "startup:enable the pm2 startup hook"
+ "logrotate:copy default logrotate configuration"
+ "ecosystem:generate a process conf file. (mode = null or simple)"
+ "reset:reset counters for process"
+ "describe:describe all parameters of a process id"
+ "list:list all processes"
+ "jlist:list all processes in JSON format"
+ "prettylist:print json in a prettified JSON"
+ "monit:launch termcaps monitoring"
+ "imonit:launch legacy termcaps monitoring"
+ "dashboard:launch dashboard with monitoring and logs"
+ "flush:flush logs"
+ "reloadLogs:reload all logs"
+ "logs:stream logs file. Default stream all logs"
+ "kill:kill daemon"
+ "pull:updates repository for a given app"
+ "forward:updates repository to the next commit for a given app"
+ "backward:downgrades repository to the previous commit for a given app"
+ "deepUpdate:performs a deep update of PM2"
+ "serve:serve a directory over http via port"
+ "examples:display pm2 usage examples"
+)
+
+local -a id_names
+
+_id_names() {
+ local app_list
+ app_list=`pm2 list -m`
+
+ local -a names ids
+ names=(`echo $app_list | grep '+---' | awk '{print $2}'`)
+ ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`)
+
+ if (( ${#ids} > 0 )); then
+ for i in {1..${#ids}}; do
+ id_names+=( "${ids[i]}:${names[i]}" )
+ done
+ fi
+}
+
+_arguments \
+ '(-v --version)'{-v,--version}'[output version]' \
+ '(-h --help)'{-h,--help}'[output usage information]' \
+ '*:: :->subcmds' && return 0
+
+if (( CURRENT == 1 )); then
+ _describe "command" _1st_arguments
+ return
+fi
+
+local -a id_comp id_all_comp id_all_files_comp start_options logs_options
+id_comp=('1: :->id_comp')
+id_all_comp=('1: :->id_all_comp')
+id_all_files_comp=('1: :->id_all_files_comp')
+start_options=(
+ '--watch[Watch folder for changes]'
+ '--fresh[Rebuild Dockerfile]'
+ '--daemon[Run container in Daemon mode (debug purposes)]'
+ '--container[Start application in container mode]'
+ '--dist[with --container; change local Dockerfile to containerize all files in current directory]'
+ '--image-name[with --dist; set the exported image name]'
+ '--node-version[with --container, set a specific major Node.js version]'
+ '--dockerdaemon[for debugging purpose]'
+ '(-h --help)'{-h,--help}'[output usage information]'
+ $id_all_files_comp
+)
+logs_options=(
+ '--json[json log output]'
+ '--format[formated log output]'
+ '--raw[raw output]'
+ '--err[only shows error output]'
+ '--out[only shows standard output]'
+ '--lines[output the last N lines, instead of the last 15 by default]'
+ '--timestamp[add timestamps (default format YYYY-MM-DD-HH:mm:ss)]'
+ '--nostream[print logs without lauching the log stream]'
+ '(-h --help)'{-h,--help}'[output usage information]'
+ $id_all_comp
+)
+
+case "$words[1]" in
+ start)
+ _arguments $start_options && return 0
+ ;;
+ logs)
+ _arguments $logs_options && return 0
+ ;;
+ stop|restart|delete|reload|reset)
+ _arguments $id_all_comp && return 0
+ ;;
+ env|inspect|monitor|unmonitor|discribe)
+ _arguments $id_comp && return 0
+ ;;
+ deploy|startOrRestart|startOrReload)
+ _files ;;
+esac
+
+case "$state" in
+ id_comp)
+ _id_names
+ _alternative \
+ 'args:app args:(($id_names))'
+ ;;
+ id_all_comp)
+ _id_names
+ id_names+=(all)
+ _alternative \
+ 'args:app args:(($id_names))'
+ ;;
+ id_all_files_comp)
+ _id_names
+ id_names+=(all)
+ _alternative \
+ 'args:app args:(($id_names))' \
+ 'files:filename:_files'
+ ;;
+esac
diff --git a/plugins/pm2/pm2.plugin.zsh b/plugins/pm2/pm2.plugin.zsh
new file mode 100644
index 000000000..f05d8db8b
--- /dev/null
+++ b/plugins/pm2/pm2.plugin.zsh
@@ -0,0 +1,6 @@
+alias p2s='pm2 start'
+alias p2o='pm2 stop'
+alias p2d='pm2 delete'
+alias p2r='pm2 restart'
+alias p2i='pm2 list'
+alias p2l='pm2 logs'