2 次代码提交 09a9467200 ... 1b5af717a9

作者 SHA1 备注 提交日期
  Carlo Sala 1b5af717a9 fix(pm2): update completion 1 月之前
  nervo 9ae155336f feat(scw): use official scw completion (#12755) 1 月之前
共有 4 个文件被更改,包括 320 次插入431 次删除
  1. 300 94
      plugins/pm2/_pm2
  2. 6 4
      plugins/scw/README.md
  3. 0 333
      plugins/scw/_scw
  4. 14 0
      plugins/scw/scw.plugin.zsh

+ 300 - 94
plugins/pm2/_pm2

@@ -1,16 +1,233 @@
-#!/bin/zsh -f
 #compdef pm2
-#autoload
+# ------------------------------------------------------------------------------
+# Description
+# -----------
+#
+#  Completion script for pm2 5.2.2 (https://pm2.keymetrics.io/).
+#
+# ------------------------------------------------------------------------------
+# Authors
+# -------
+#
+#  * Myoungdo Park <mdo.park@gmail.com>
+#  * Shohei Yoshida <https://github.com/syohex>
+#
+# ------------------------------------------------------------------------------
 
-local -a _1st_arguments
+_pm2() {
+  typeset -A opt_args
+  local context state line
 
-_1st_arguments=(
+  local curcontext="$curcontext"
+
+  local ret=1
+
+  _arguments -C \
+    '(- *)'{-v,-V,--version}'[print pm2 version]' \
+    '(-s --silent)'{-s,--silent}'[hide all messages]' \
+    '--ext[watch only this file extension]:extension' \
+    '(-n --name)'{-n,--name}'[set a name for the process in the process list]:name' \
+    '(-m --mini-list)'{-m,--mini-list}'[display a compacted list without formatting]' \
+    '--interpreter[set a specific interpreter to use for executing app(default: node)]:prog' \
+    '(--interpreter-args --node-args)'{--interpreter-args,--node-args}'[set arguments to pass to the interpreter]:args' \
+    '(-o --output)'{-o,--output}'[specify log file for stdout]: :_files' \
+    '(-e --error)'{-e,--error}'[specify log file for stderr]: :_files' \
+    '(-l --log)'{-l,--log}'[specify log file which gathers both stdout and stderr]' \
+    '--filter-env[filter out outgoing global values that contain provided strings]:envs' \
+    '--log-type[specify log output style]: :(raw json)' \
+    '--log-date-format[specify log output style]:format' \
+    '--time[enable time logging]' \
+    '--disable-logs[disable all logs storage]' \
+    '*--env[specify which set of environment variables from ecosystem file must be injected]:env' \
+    '(-a --update-env)'{-a,--update-env}'[force and update of the environment with restart/reload]' \
+    '(-f --force)'{-f,--force}'[force actions]' \
+    '(-i --instances)'{-i,--instances}'[launch number instances]:num' \
+    '--parallel[number of parallel actions]:num' \
+    '--shutdown-with-message[shutdown an application with process.send("shutdown") instead of process.kill(pid, SIGINT)]' \
+    '(-p --pid)'{-p,--pid}'[specify pid file]: :_files' \
+    '(-k --kill-timeout)'{-k,--kill-timeout}'[delay before sending final SIGKILL signal to process]:delay' \
+    '--listen-timeout[listen timeout an application reload]:delay' \
+    '--max-memory-restart[restart the app if an amount of memory is exceeded (in bytes)]:bytes' \
+    '--restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
+    '--exp-backoff-restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
+    '(-x --execute-command)'{-e,--execute-command}'[execute a program using fork system]' \
+    '--max-restarts[only start the script COUNT times]:count' \
+    '(-u --user)'{-u,--user}'[define user when generating startup script]:username' \
+    '--uid[run target script with <uid> rights]:uid' \
+    '--gid[run target script with <gid> rights]:gui' \
+    '--namespace[start application within specified namespace]:namespace' \
+    '--cwd[run target script from path <cwd>]:cwd:_paths -/' \
+    '--hp[define home path when generating startup script]: :_paths -/' \
+    '--wait-ip[override systemd script to wait for full internet connectivity to launch pm2]' \
+    '--service-name[define service name when generating startup script]' \
+    '(-c --cron --cron-restart)'{-c,--cron,--cron-restart}'[restart a running process based on a cron pattern]:pattern' \
+    '(-w --write)'{-w,--write}'[write configuration in local folder]' \
+    '--no-daemon[run pm2 daemon in the foreground if it does not exist already]' \
+    '(--disable-source-map-support --source-map-support)--source-map-support[force source map support]' \
+    '--only[with json declaration, allow to only act on one application]:app' \
+    '(--disable-source-map-support --source-map-support)--disable-source-map-support[force disable source map support]' \
+    '--wait-ready[ask pm2 to wait for ready event from your app]' \
+    '--merge-logs[merge logs from different instances but keep error and out separated]' \
+    '*--watch[watch application folder for changes]: :_files -/' \
+    '*--ignore-watch[list of paths to ignore]: :_files' \
+    '--no-color[skip colors]' \
+    '--no-vizion[start an app without vizion feature]' \
+    '--np-autorestart[start an app without automatic restart]' \
+    '--no-treekill[Only kill the main process, not detached children]' \
+    '--no-pmx[start an app without pmx]' \
+    '--no-automation[start an app without automation]' \
+    '(--disable-trace --trace)--trace[enable transaction tracing with km]' \
+    '(--disable-trace --trace)--disable-trace[disable transaction tracing with km]' \
+    "--sort[sort process according to field's]:field_name" \
+    '--attach[attach logging after your start/restart/stop/reload]' \
+    '--v8[enable v8 data collecting]' \
+    '--event-loop-inspector[enable event-loop-inspector dump in pmx]' \
+    '--deep-monitoring[enable all monitoring tools]' \
+    '(- *)'{-h,--help}'[output usage information]' \
+    '1: :_pm2_subcommands' \
+    '*:: :->subcmds' && return 0
+
+  case "$state" in
+    (subcmds)
+      case $words[1] in
+        (start)
+          _arguments \
+            '--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]:name' \
+            '--node-version[with --container, set a specific major Node.js version]:version' \
+            '--dockerdaemon[for debugging purpose]' \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '*: :_pm2_id_namespace_file' \
+            && ret=0
+          ;;
+        (trigger)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '1: :_pm2_id_names' \
+            && ret=0
+          ;;
+        (deploy|startOrRestart|startOrReload|startOrGracefulReload)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '1: :_files -g "*.json"' \
+            && ret=0
+          ;;
+        (stop|restart)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--watch[Stop watching folder for changes]' \
+            '*: :_pm2_id_namespace_all' \
+            && ret=0
+          ;;
+        (reload|delete|reset)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '*: :_pm2_id_namespace_all' \
+            && ret=0
+          ;;
+        (module:install)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--tarball[is local tarball]' \
+            '--install[run yarn install before starting module]' \
+            '--docker[is docker container]' \
+            '--v1[install module in v1 manner(do not use it)]' \
+            '--safe[keep module backup, if new module fail = restore with previous]:time' \
+            && ret=0
+          ;;
+        (publish|module:publish)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--npm[publish on npm]' \
+            '*: :_files -/' \
+            && ret=0
+          ;;
+        (link)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--info-node[set url info node]:url' \
+            && ret=0
+          ;;
+        (plus)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--info-node[set url info node]:url' \
+            '(-d --discrete)'{-d,--discrete}'[silent mode]' \
+            '(-a --install-all)'{-a,--install-all}'[install all modules (force yes)]' \
+            && ret=0
+          ;;
+        (dump|save)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--force[force deletion of dump file even if empty]' \
+            && ret=0
+          ;;
+        (send|attach|describe|env)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '1: :_pm2_id_names' \
+            && ret=0
+          ;;
+        (slist|sysinfos)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--tree[show as tree]' \
+            && ret=0
+          ;;
+        (logs)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--json[json log output]' \
+            '--format[formatted log output]' \
+            '--raw[raw output]' \
+            '--err[only shows error output]' \
+            '--out[only shows standard output]' \
+            '--line[output the last N lines, instead of the last 15 by default]:lines' \
+            '--timestamp[add timestamps(default format YYYY-MM-DD-HH:mm:ss)]:format' \
+            '--nostream[print logs without launching the log stream]' \
+            '*--highlight[highlights the given value]' \
+            '1: :_pm2_id_namespace' \
+            && ret=0
+          ;;
+        (serve)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '--port[specify port to listen to]:port' \
+            '--spa[always serving index.html on inexistent sub path]' \
+            '--basic-auth-username[set basic auth username]:username' \
+            '--basic-auth-password[set basic auth password]:password' \
+            '--monitor[frontend app monitoring]:app' \
+            '*: :_files -/' \
+            && ret=0
+          ;;
+        (*)
+          _arguments \
+            '(- *)'{-h,--help}'[output usage information]' \
+            '*: :_files' \
+            && ret=0
+          ;;
+      esac
+      ;;
+  esac
+
+  return ret
+}
+
+(( $+functions[_pm2_subcommands] )) ||
+_pm2_subcommands() {
+  local -a subcommands=(
     "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"
+    "create:return pid of [app_name] or all"
+    "startOrGracefulReload:start or gracefully reload JSON file"
     "stop:stop a process"
     "restart:restart a process"
     "scale:scale up/down a process in cluster mode depending on total_number param"
@@ -23,18 +240,23 @@ _1st_arguments=(
     "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"
+    "update:update in-memory PM2 with local PM2"
     "install:install or update a module and run it forever"
+    "module\: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"
+    "module\:uninstall:stop and uninstall a module"
     "package:Check & Package TAR type module"
     "publish:Publish the module you are currently on"
+    "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>"
+    "conf:get / set module config values"
     "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"
+    "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"
@@ -43,8 +265,8 @@ _1st_arguments=(
     "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"
+    "save: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>"
@@ -52,15 +274,27 @@ _1st_arguments=(
     "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)"
+    "ecosystem:generate a process conf file"
+    "init:generate a process conf file"
     "reset:reset counters for process"
-    "describe:describe all parameters of a process id"
+    "describe:describe all parameters of a process"
+    "desc:describe all parameters of a process"
+    "info:describe all parameters of a process"
+    "show:describe all parameters of a process"
+    "env:list all environment variables of a process id"
     "list:list all processes"
+    "l:list all processes"
+    "ps:list all processes"
+    "status:list all processes"
     "jlist:list all processes in JSON format"
+    "sysmonit:start system monitoring daemon"
+    "slist:list system infos in JSON"
+    "sysinfos:list system infos in JSON"
     "prettylist:print json in a prettified JSON"
     "monit:launch termcaps monitoring"
     "imonit:launch legacy termcaps monitoring"
     "dashboard:launch dashboard with monitoring and logs"
+    "dash:launch dashboard with monitoring and logs"
     "flush:flush logs"
     "reloadLogs:reload all logs"
     "logs:stream logs file. Default stream all logs"
@@ -70,99 +304,71 @@ _1st_arguments=(
     "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"
+    "autoinstall:auto install"
     "examples:display pm2 usage examples"
-)
+  )
 
-local -a id_names
+  _describe -t subcommands 'subcommand' subcommands "$@"
+}
 
-_id_names() {
-    local app_list
-    app_list=`pm2 list -m`
+(( $+functions[_pm2_id_names] )) ||
+_pm2_id_names() {
+  local app_list=$(pm2 list -m)
+  local -a names=(${(@f)"$(echo $app_list | awk '/^\+---/{sub("+--- ", ""); print}')"})
+  local -a ids=(${(@f)"$(echo $app_list | awk '/^pm2 id/{sub("pm2 id :", ""); print}')"})
 
-    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
+    local -a id_names
+    for i in {1..${#ids}}; do
+      id_names+=( "${ids[i]}:${names[i]}" )
+    done
 
-    if (( ${#ids} > 0 )); then
-        for i in {1..${#ids}}; do
-            id_names+=( "${ids[i]}:${names[i]}" )
-        done
-    fi
+    _describe 'id' id_names
+  fi
 }
 
-_arguments \
-    '(-v --version)'{-v,--version}'[output version]' \
-    '(-h --help)'{-h,--help}'[output usage information]' \
-    '*:: :->subcmds' && return 0
+(( $+functions[_pm2_namespaces] )) ||
+_pm2_namespaces() {
+  local -a namespaces=(${(@f)"$(pm2 list -m | awk '/^namespace :/{ print $3 }')"})
+  if (( ${#namespaces} > 0 )); then
+    _values 'namespace' $namespaces
+  fi
+}
+
+(( $+functions[_pm2_id_namespace] )) ||
+_pm2_id_namespace() {
+  _alternative \
+    'ids:id:_pm2_id_names' \
+    'namespaces:namespace:_pm2_namespaces'
+}
+
+(( $+functions[_pm2_id_namespace_all] )) ||
+_pm2_id_namespace_all() {
+  _alternative \
+    'ids:id:_pm2_id_names' \
+    'namespaces:namespace:_pm2_namespaces' \
+    'all:all:(all)'
+}
+
+(( $+functions[_pm2_id_namespace_file] )) ||
+_pm2_id_namespace_file() {
+  _alternative \
+    'ids:id:_pm2_id_names' \
+    'namespaces:namespace:_pm2_namespaces' \
+    'files:file:_files'
+}
 
-if (( CURRENT == 1 )); then
-    _describe "command" _1st_arguments
-    return
+if [ "$funcstack[1]" = "_pm2" ]; then
+    _pm2 "$@"
+else
+    compdef _pm2 pm2
 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[formatted 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 launching 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|describe)
-        _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
+# Local Variables:
+# mode: Shell-Script
+# sh-indentation: 2
+# indent-tabs-mode: nil
+# sh-basic-offset: 2
+# End:
+
+# vim: ft=zsh sw=2 ts=2 et

+ 6 - 4
plugins/scw/README.md

@@ -1,7 +1,9 @@
-## Scaleway CLI autocomplete plugin
+## Scaleway CLI plugin
 
-[scw](https://github.com/scaleway/scaleway-cli): Manage Bare Metal servers from Command Line (as easily as with Docker)
+This plugin adds completion for [scw](https://github.com/scaleway/scaleway-cli), the command line interface for Scaleway.
 
-- Adds autocomplete options for all `scw` commands.
+To use it, add `scw` to the plugins array in your zshrc file:
 
-Maintainer : Manfred Touron ([@moul](https://github.com/moul))
+```zsh
+plugins=(... scw)
+```

+ 0 - 333
plugins/scw/_scw

@@ -1,333 +0,0 @@
-#compdef scw
-#
-# zsh completion for scw (https://www.scaleway.com)
-#
-# Inspired by https://github.com/felixr/docker-zsh-completion
-
-__scw_get_servers() {
-    local expl
-    declare -a servers
-    servers=(${(f)"$(_call_program commands scw _completion servers-names)"})
-    _describe -t servers "servers" servers
-}
-
-__scw_stoppedservers() {
-    __scw_get_servers
-}
-
-__scw_runningservers() {
-    __scw_get_servers
-}
-
-__scw_servers () {
-    __scw_get_servers
-}
-
-__scw_images () {
-    local expl
-    declare -a images
-    images=(${(f)"$(_call_program commands scw _completion images-names)"})
-    _describe -t images "images" images
-}
-
-__scw_images_and_snapshots () {
-    __scw_images
-    __scw_snapshots
-}
-
-__scw_snapshots () {
-    local expl
-    declare -a snapshots
-    snapshots=(${(f)"$(_call_program commands scw _completion --prefix snapshots-names)"})
-    _describe -t snapshots "snapshots" snapshots
-}
-
-__scw_bootscripts () {
-    local expl
-    declare -a bootscripts
-    bootscripts=(${(f)"$(_call_program commands scw _completion bootscripts-names)"})
-    _describe -t bootscripts "bootscripts" bootscripts
-}
-
-__scw_tags() {
-    __scw_images
-}
-
-__scw_repositories_with_tags() {
-    __scw_images
-}
-
-__scw_search() {
-    # declare -a scwsearch
-    local cache_policy
-    zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
-    if [[ -z "$cache_policy" ]]; then
-        zstyle ":completion:${curcontext}:" cache-policy __scw_caching_policy
-    fi
-
-    local searchterm cachename
-    searchterm="${words[$CURRENT]%/}"
-    cachename=_scw-search-$searchterm
-
-    local expl
-    local -a result
-    if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
-        && ! _retrieve_cache ${cachename#_}; then
-        _message "Searching for ${searchterm}..."
-        result=(${${${(f)"$(_call_program commands scw search ${searchterm})"}%% *}[2,-1]})
-        _store_cache ${cachename#_} result
-    fi
-    _wanted scwsearch expl 'available images' compadd -a result
-}
-
-__scw_caching_policy()
-{
-  oldp=( "$1"(Nmh+1) )     # 1 hour
-  (( $#oldp ))
-}
-
-
-__scw_repositories () {
-    __scw_images
-}
-
-__scw_commands () {
-    # local -a  _scw_subcommands
-    local cache_policy
-
-    zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
-    if [[ -z "$cache_policy" ]]; then
-        zstyle ":completion:${curcontext}:" cache-policy __scw_caching_policy
-    fi
-
-    if ( [[ ${+_scw_subcommands} -eq 0 ]] || _cache_invalid scw_subcommands) \
-        && ! _retrieve_cache scw_subcommands;
-    then
-        local -a lines
-        lines=(${(f)"$(_call_program commands scw 2>&1)"})
-        _scw_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I)    *]}]}## #}/ ##/:})
-        _scw_subcommands=($_scw_subcommands 'help:Show help for a command')
-        _store_cache scw_subcommands _scw_subcommands
-    fi
-    _describe -t scw-commands "scw command" _scw_subcommands
-}
-
-__scw_subcommand () {
-    local -a _command_args
-    case "$words[1]" in
-        (attach)
-            _arguments \
-                '--no-stdin[Do not attach stdin]' \
-                ':servers:__scw_runningservers'
-            ;;
-        (commit)
-            _arguments \
-                {-v,--volume=0}'[Volume slot]:volume: ' \
-                ':server:__scw_servers' \
-                ':repository:__scw_repositories_with_tags'
-            ;;
-        (cp)
-            _arguments \
-                ':server:->server' \
-                ':hostpath:_files'
-            case $state in
-                (server)
-                    if compset -P '*:'; then
-                        _files
-                    else
-                        __scw_servers -qS ":"
-                    fi
-                    ;;
-            esac
-            ;;
-        (exec)
-            local state ret
-            _arguments \
-                {-T,--timeout=0}'[Set timeout values to seconds]' \
-                {-w,--wait}'[Wait for SSH to be ready]' \
-                ':servers:__scw_runningservers' \
-                '*::command:->anycommand' && ret=0
-
-            case $state in
-                (anycommand)
-                    shift 1 words
-                    (( CURRENT-- ))
-                    _normal
-                    ;;
-            esac
-
-            return ret
-            ;;
-        (history)
-            _arguments \
-                '--no-trunc[Do not truncate output]' \
-                {-q,--quiet}'[Only show numeric IDs]' \
-                '*:images:__scw_images'
-            ;;
-        (images)
-            _arguments \
-                {-a,--all}'[Show all images]' \
-                '--no-trunc[Do not truncate output]' \
-                {-q,--quiet}'[Only show numeric IDs]' \
-                ':repository:__scw_repositories'
-            ;;
-        (info)
-            ;;
-        (inspect)
-            _arguments \
-                {-f,--format=-}'[Format the output using the given go template]:template: ' \
-                '*:servers:__scw_servers'
-            ;;
-        (kill)
-            _arguments \
-                '*:servers:__scw_runningservers'
-            ;;
-        (login)
-            _arguments \
-                {-o,--organization=-}'[Organization]:organization: ' \
-                {-t,--token=-}'[Token]:token: ' \
-                ':server: '
-            ;;
-        (logout)
-            _arguments \
-                ':server: '
-            ;;
-        (logs)
-            _arguments \
-                '*:servers:__scw_servers'
-            ;;
-        (port)
-            _arguments \
-                '1:servers:__scw_runningservers' \
-                '2:port:_ports'
-            ;;
-        (start)
-            _arguments \
-                {-T,--timeout=0}'[Set timeout values to seconds]' \
-                {-w,--wait}'[Wait for SSH to be ready]' \
-                '*:servers:__scw_stoppedservers'
-            ;;
-        (rm)
-            _arguments \
-                '*:servers:__scw_stoppedservers'
-            ;;
-        (rmi)
-            _arguments \
-                '*:images:__scw_images'
-            ;;
-        (restart)
-            _arguments \
-                '*:servers:__scw_runningservers'
-            ;;
-        (stop)
-            _arguments \
-                {-t,--terminate}'[Stop and trash a server with its volumes]' \
-                {-w,--wait}'[Synchronous stop. Wait for server to be stopped]' \
-                '*:servers:__scw_runningservers'
-            ;;
-        (top)
-            _arguments \
-                '1:servers:__scw_runningservers' \
-                '(-)*:: :->ps-arguments'
-            case $state in
-                (ps-arguments)
-                    _ps
-                    ;;
-            esac
-            ;;
-        (ps)
-            _arguments \
-                {-a,--all}'[Show all servers. Only running servers are shown by default]' \
-                {-l,--latest}'[Show only the latest created server]' \
-                '-n[Show n last created servers, include non-running one]:n:(1 5 10 25 50)' \
-                '--no-trunc[Do not truncate output]' \
-                {-q,--quiet}'[Only show numeric IDs]'
-            ;;
-        (tag)
-            _arguments \
-                {-f,--force}'[force]'\
-                ':image:__scw_images'\
-                ':repository:__scw_repositories_with_tags'
-            ;;
-        (create|run)
-            _arguments \
-                {-a,--attach}'[Attach to stdin, stdout or stderr]' \
-                '*'{-e,--environment=-}'[Set environment variables]:environment variable: ' \
-                '--name=-[Server name]:name: ' \
-                '--bootscript=-[Assign a bootscript]:bootscript:__scw_bootscripts ' \
-                '*-v[Bind mount a volume]:volume: '\
-                '(-):images:__scw_images_and_snapshots' \
-                '(-):command: _command_names -e' \
-                '*::arguments: _normal'
-
-            case $state in
-                (link)
-                    if compset -P '*:'; then
-                        _wanted alias expl 'Alias' compadd -E ""
-                    else
-                        __scw_runningservers -qS ":"
-                    fi
-                    ;;
-            esac
-            ;;
-        (rename)
-            _arguments \
-                ':old name:__scw_servers' \
-                ':new name: '
-            ;;
-        (search)
-            _arguments \
-                '--no-trunc[Do not truncate output]' \
-                ':term: '
-            ;;
-        (wait)
-            _arguments '*:servers:__scw_runningservers'
-            ;;
-        (help)
-            _arguments ':subcommand:__scw_commands'
-            ;;
-        (*)
-            _message 'Unknown sub command'
-    esac
-
-}
-
-_scw () {
-    # Support for subservices, which allows for `compdef _scw scw-shell=_scw_servers`.
-    # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
-    if [[ $service != scw ]]; then
-        _call_function - _$service
-        return
-    fi
-
-    local curcontext="$curcontext" state line
-    typeset -A opt_args
-
-    _arguments -C \
-      '-H[tcp://host:port to bind/connect to]:socket: ' \
-         '(-): :->command' \
-         '(-)*:: :->option-or-argument'
-
-    if (( CURRENT == 1 )); then
-
-    fi
-    case $state in
-        (command)
-            __scw_commands
-            ;;
-        (option-or-argument)
-            curcontext=${curcontext%:*:*}:scw-$words[1]:
-            __scw_subcommand
-            ;;
-    esac
-}
-
-_scw "$@"
-
-# Local Variables:
-# mode: Shell-Script
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# sh-basic-offset: 4
-# End:
-# vim: ft=zsh sw=4 ts=4 et

+ 14 - 0
plugins/scw/scw.plugin.zsh

@@ -0,0 +1,14 @@
+if (( ! $+commands[scw] )); then
+  return
+fi
+
+_scw () {
+  output=($(scw autocomplete complete zsh -- ${CURRENT} ${words}))
+  opts=('-S' ' ')
+  if [[ $output == *= ]]; then
+    opts=('-S' '')
+  fi
+  compadd "${opts[@]}" -- "${output[@]}"
+}
+
+compdef _scw scw