github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/contrib/completion/zsh/_docker (about)

     1  #compdef docker
     2  #
     3  # zsh completion for docker (http://docker.com)
     4  #
     5  # version:  0.3.0
     6  # github:   https://github.com/felixr/docker-zsh-completion
     7  #
     8  # contributors:
     9  #   - Felix Riedel
    10  #   - Steve Durrheimer
    11  #   - Vincent Bernat
    12  #
    13  # license:
    14  #
    15  # Copyright (c) 2013, Felix Riedel
    16  # All rights reserved.
    17  #
    18  # Redistribution and use in source and binary forms, with or without
    19  # modification, are permitted provided that the following conditions are met:
    20  #     * Redistributions of source code must retain the above copyright
    21  #       notice, this list of conditions and the following disclaimer.
    22  #     * Redistributions in binary form must reproduce the above copyright
    23  #       notice, this list of conditions and the following disclaimer in the
    24  #       documentation and/or other materials provided with the distribution.
    25  #     * Neither the name of the <organization> nor the
    26  #       names of its contributors may be used to endorse or promote products
    27  #       derived from this software without specific prior written permission.
    28  #
    29  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    30  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    31  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    32  # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    33  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    34  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    35  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    36  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    37  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    38  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    39  #
    40  
    41  __docker_get_containers() {
    42      [[ $PREFIX = -* ]] && return 1
    43      integer ret=1
    44      local kind
    45      declare -a running stopped lines args
    46  
    47      kind=$1
    48      shift
    49      [[ $kind = (stopped|all) ]] && args=($args -a)
    50  
    51      lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"})
    52  
    53      # Parse header line to find columns
    54      local i=1 j=1 k header=${lines[1]}
    55      declare -A begin end
    56      while (( j < ${#header} - 1 )); do
    57          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
    58          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
    59          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
    60          begin[${header[$i,$((j-1))]}]=$i
    61          end[${header[$i,$((j-1))]}]=$k
    62      done
    63      lines=(${lines[2,-1]})
    64  
    65      # Container ID
    66      local line
    67      local s
    68      for line in $lines; do
    69          s="${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"
    70          s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    71          s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    72          if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    73              stopped=($stopped $s)
    74          else
    75              running=($running $s)
    76          fi
    77      done
    78  
    79      # Names
    80      local name
    81      local -a names
    82      for line in $lines; do
    83          names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}})
    84          for name in $names; do
    85              s="${name}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    86              s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    87              if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    88                  stopped=($stopped ${s#*/})
    89              else
    90                  running=($running ${s#*/})
    91              fi
    92          done
    93      done
    94  
    95      [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0
    96      [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0
    97      return ret
    98  }
    99  
   100  __docker_stoppedcontainers() {
   101      [[ $PREFIX = -* ]] && return 1
   102      __docker_get_containers stopped "$@"
   103  }
   104  
   105  __docker_runningcontainers() {
   106      [[ $PREFIX = -* ]] && return 1
   107      __docker_get_containers running "$@"
   108  }
   109  
   110  __docker_containers() {
   111      [[ $PREFIX = -* ]] && return 1
   112      __docker_get_containers all "$@"
   113  }
   114  
   115  __docker_images() {
   116      [[ $PREFIX = -* ]] && return 1
   117      integer ret=1
   118      declare -a images
   119      images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
   120      _describe -t docker-images "images" images && ret=0
   121      __docker_repositories_with_tags && ret=0
   122      return ret
   123  }
   124  
   125  __docker_repositories() {
   126      [[ $PREFIX = -* ]] && return 1
   127      declare -a repos
   128      repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
   129      repos=(${repos#<none>})
   130      _describe -t docker-repos "repositories" repos
   131  }
   132  
   133  __docker_repositories_with_tags() {
   134      [[ $PREFIX = -* ]] && return 1
   135      integer ret=1
   136      declare -a repos onlyrepos matched
   137      declare m
   138      repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *})
   139      repos=(${${repos%:::<none>}#<none>})
   140      # Check if we have a prefix-match for the current prefix.
   141      onlyrepos=(${repos%::*})
   142      for m in $onlyrepos; do
   143          [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && {
   144              # Yes, complete with tags
   145              repos=(${${repos/:::/:}/:/\\:})
   146              _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0
   147              return ret
   148          }
   149      done
   150      # No, only complete repositories
   151      onlyrepos=(${${repos%:::*}/:/\\:})
   152      _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0
   153  
   154      return ret
   155  }
   156  
   157  __docker_search() {
   158      [[ $PREFIX = -* ]] && return 1
   159      local cache_policy
   160      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   161      if [[ -z "$cache_policy" ]]; then
   162          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   163      fi
   164  
   165      local searchterm cachename
   166      searchterm="${words[$CURRENT]%/}"
   167      cachename=_docker-search-$searchterm
   168  
   169      local expl
   170      local -a result
   171      if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
   172          && ! _retrieve_cache ${cachename#_}; then
   173          _message "Searching for ${searchterm}..."
   174          result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]})
   175          _store_cache ${cachename#_} result
   176      fi
   177      _wanted dockersearch expl 'available images' compadd -a result
   178  }
   179  
   180  __docker_caching_policy() {
   181    oldp=( "$1"(Nmh+1) )     # 1 hour
   182    (( $#oldp ))
   183  }
   184  
   185  __docker_commands() {
   186      local cache_policy
   187  
   188      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   189      if [[ -z "$cache_policy" ]]; then
   190          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   191      fi
   192  
   193      if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
   194          && ! _retrieve_cache docker_subcommands;
   195      then
   196          local -a lines
   197          lines=(${(f)"$(_call_program commands docker 2>&1)"})
   198          _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I)    *]}]}## #}/ ##/:})
   199          _docker_subcommands=($_docker_subcommands 'help:Show help for a command')
   200          _store_cache docker_subcommands _docker_subcommands
   201      fi
   202      _describe -t docker-commands "docker command" _docker_subcommands
   203  }
   204  
   205  __docker_subcommand() {
   206      local -a _command_args opts_help opts_cpumem opts_create
   207      local expl help="-h --help"
   208      integer ret=1
   209  
   210      opts_help=("(: -)"{-h,--help}"[Print usage]")
   211      opts_cpumem=(
   212          "($help -c --cpu-shares)"{-c,--cpu-shares=-}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
   213          "($help)--cgroup-parent=-[Parent cgroup for the container]:cgroup: "
   214          "($help)--cpu-period=-[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
   215          "($help)--cpu-quota=-[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
   216          "($help)--cpuset-cpus=-[CPUs in which to allow execution]:CPUs: "
   217          "($help)--cpuset-mems=-[MEMs in which to allow execution]:MEMs: "
   218          "($help -m --memory)"{-m,--memory=-}"[Memory limit]:Memory limit: "
   219          "($help)--memory-swap=-[Total memory limit with swap]:Memory limit: "
   220      )
   221      opts_create=(
   222          "($help -a --attach)"{-a,--attach=-}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
   223          "($help)*--add-host=-[Add a custom host-to-IP mapping]:host\:ip mapping: "
   224          "($help)--blkio-weight=-[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
   225          "($help)*--cap-add=-[Add Linux capabilities]:capability: "
   226          "($help)*--cap-drop=-[Drop Linux capabilities]:capability: "
   227          "($help)--cidfile=-[Write the container ID to the file]:CID file:_files"
   228          "($help)*--device=-[Add a host device to the container]:device:_files"
   229          "($help)*--dns=-[Set custom DNS servers]:DNS server: "
   230          "($help)*--dns-opt=-[Set custom DNS options]:DNS option: "
   231          "($help)*--dns-search=-[Set custom DNS search domains]:DNS domains: "
   232          "($help)*"{-e,--env=-}"[Set environment variables]:environment variable: "
   233          "($help)--entrypoint=-[Overwrite the default entrypoint of the image]:entry point: "
   234          "($help)*--env-file=-[Read environment variables from a file]:environment file:_files"
   235          "($help)*--expose=-[Expose a port from the container without publishing it]: "
   236          "($help)*--group-add=-[Add additional groups to run as]:group:_groups"
   237          "($help -h --hostname)"{-h,--hostname=-}"[Container host name]:hostname:_hosts"
   238          "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
   239          "($help)--ipc=-[IPC namespace to use]:IPC namespace: "
   240          "($help)*--link=-[Add link to another container]:link:->link"
   241          "($help)*"{-l,--label=-}"[Set meta data on a container]:label: "
   242          "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs none)"
   243          "($help)*--log-opt=-[Log driver specific options]:log driver options: "
   244          "($help)*--lxc-conf=-[Add custom lxc options]:lxc options: "
   245          "($help)--mac-address=-[Container MAC address]:MAC address: "
   246          "($help)--name=-[Container name]:name: "
   247          "($help)--net=-[Network mode]:network mode:(bridge none container host)"
   248          "($help)--oom-kill-disable[Disable OOM Killer]"
   249          "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
   250          "($help)*"{-p,--publish=-}"[Expose a container's port to the host]:port:_ports"
   251          "($help)--pid=-[PID namespace to use]:PID: "
   252          "($help)--privileged[Give extended privileges to this container]"
   253          "($help)--read-only[Mount the container's root filesystem as read only]"
   254          "($help)--restart=-[Restart policy]:restart policy:(no on-failure always)"
   255          "($help)*--security-opt=-[Security options]:security option: "
   256          "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
   257          "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users"
   258          "($help)*--ulimit=-[ulimit options]:ulimit: "
   259          "($help)*-v[Bind mount a volume]:volume: "
   260          "($help)*--volumes-from=-[Mount volumes from the specified container]:volume: "
   261          "($help -w --workdir)"{-w,--workdir=-}"[Working directory inside the container]:directory:_directories"
   262      )
   263  
   264      case "$words[1]" in
   265          (attach)
   266              _arguments \
   267                  $opts_help \
   268                  "($help)--no-stdin[Do not attach stdin]" \
   269                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   270                  "($help -):containers:__docker_runningcontainers" && ret=0
   271              ;;
   272          (build)
   273              _arguments \
   274                  $opts_help \
   275                  $opts_cpumem \
   276                  "($help -f --file)"{-f,--file=-}"[Name of the Dockerfile]:Dockerfile:_files" \
   277                  "($help)--force-rm[Always remove intermediate containers]" \
   278                  "($help)--no-cache[Do not use cache when building the image]" \
   279                  "($help)--pull[Attempt to pull a newer version of the image]" \
   280                  "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
   281                  "($help)--rm[Remove intermediate containers after a successful build]" \
   282                  "($help -t --tag)"{-t,--tag=-}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
   283                  "($help -):path or URL:_directories" && ret=0
   284              ;;
   285          (commit)
   286              _arguments \
   287                  $opts_help \
   288                  "($help -a --author)"{-a,--author=-}"[Author]:author: " \
   289                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   290                  "($help -m --message)"{-m,--message=-}"[Commit message]:message: " \
   291                  "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
   292                  "($help -):container:__docker_containers" \
   293                  "($help -): :__docker_repositories_with_tags" && ret=0
   294              ;;
   295          (cp)
   296              _arguments \
   297                  $opts_help \
   298                  "($help -)1:container:->container" \
   299                  "($help -)2:hostpath:_files" && ret=0
   300              case $state in
   301                  (container)
   302                      if compset -P "*:"; then
   303                          _files && ret=0
   304                      else
   305                          __docker_containers -qS ":" && ret=0
   306                      fi
   307                      ;;
   308              esac
   309              ;;
   310          (create)
   311              _arguments \
   312                  $opts_help \
   313                  $opts_cpumem \
   314                  $opts_create \
   315                  "($help -): :__docker_images" \
   316                  "($help -):command: _command_names -e" \
   317                  "($help -)*::arguments: _normal" && ret=0
   318  
   319              case $state in
   320                  (link)
   321                      if compset -P "*:"; then
   322                          _wanted alias expl "Alias" compadd -E "" && ret=0
   323                      else
   324                          __docker_runningcontainers -qS ":" && ret=0
   325                      fi
   326                      ;;
   327              esac
   328  
   329              ;;
   330          (diff)
   331              _arguments \
   332                  $opts_help \
   333                  "($help -)*:containers:__docker_containers" && ret=0
   334              ;;
   335          (events)
   336              _arguments \
   337                  $opts_help \
   338                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   339                  "($help)--since=-[Events created since this timestamp]:timestamp: " \
   340                  "($help)--until=-[Events created until this timestamp]:timestamp: " && ret=0
   341              ;;
   342          (exec)
   343              local state
   344              _arguments \
   345                  $opts_help \
   346                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   347                  "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
   348                  "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
   349                  "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users" \
   350                  "($help -):containers:__docker_runningcontainers" \
   351                  "($help -)*::command:->anycommand" && ret=0
   352  
   353              case $state in
   354                  (anycommand)
   355                      shift 1 words
   356                      (( CURRENT-- ))
   357                      _normal && ret=0
   358                      ;;
   359              esac
   360              ;;
   361          (export)
   362              _arguments \
   363                  $opts_help \
   364                  "($help -o --output)"{-o,--output=-}"[Write to a file, instead of stdout]:output file:_files" \
   365                  "($help -)*:containers:__docker_containers" && ret=0
   366              ;;
   367          (history)
   368              _arguments \
   369                  $opts_help \
   370                  "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
   371                  "($help)--no-trunc[Do not truncate output]" \
   372                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   373                  "($help -)*: :__docker_images" && ret=0
   374              ;;
   375          (images)
   376              _arguments \
   377                  $opts_help \
   378                  "($help -a --all)"{-a,--all}"[Show all images]" \
   379                  "($help)--digest[Show digests]" \
   380                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   381                  "($help)--no-trunc[Do not truncate output]" \
   382                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   383                  "($help -): :__docker_repositories" && ret=0
   384              ;;
   385          (import)
   386              _arguments \
   387                  $opts_help \
   388                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   389                  "($help -):URL:(- http:// file://)" \
   390                  "($help -): :__docker_repositories_with_tags" && ret=0
   391              ;;
   392          (info|version)
   393              _arguments \
   394                  $opts_help && ret=0
   395              ;;
   396          (inspect)
   397              _arguments \
   398                  $opts_help \
   399                  "($help -f --format=-)"{-f,--format=-}"[Format the output using the given go template]:template: " \
   400                  "($help)--type=-[Return JSON for specified type]:type:(image container)" \
   401                  "($help -)*:containers:__docker_containers" && ret=0
   402              ;;
   403          (kill)
   404              _arguments \
   405                  $opts_help \
   406                  "($help -s --signal)"{-s,--signal=-}"[Signal to send]:signal:_signals" \
   407                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   408              ;;
   409          (load)
   410              _arguments \
   411                  $opts_help \
   412                  "($help -i --input)"{-i,--input=-}"[Read from tar archive file]:archive file:_files -g "*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)"" && ret=0
   413              ;;
   414          (login)
   415              _arguments \
   416                  $opts_help \
   417                  "($help -e --email)"{-e,--email=-}"[Email]:email: " \
   418                  "($help -p --password)"{-p,--password=-}"[Password]:password: " \
   419                  "($help -u --user)"{-u,--user=-}"[Username]:username: " \
   420                  "($help -)1:server: " && ret=0
   421              ;;
   422          (logout)
   423              _arguments \
   424                  $opts_help \
   425                  "($help -)1:server: " && ret=0
   426              ;;
   427          (logs)
   428              _arguments \
   429                  $opts_help \
   430                  "($help -f --follow)"{-f,--follow}"[Follow log output]" \
   431                  "($help -s --since)"{-s,--since=-}"[Show logs since this timestamp]:timestamp: " \
   432                  "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
   433                  "($help)--tail=-[Output the last K lines]:lines:(1 10 20 50 all)" \
   434                  "($help -)*:containers:__docker_containers" && ret=0
   435              ;;
   436          (pause|unpause)
   437              _arguments \
   438                  $opts_help \
   439                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   440              ;;
   441          (port)
   442              _arguments \
   443                  $opts_help \
   444                  "($help -)1:containers:__docker_runningcontainers" \
   445                  "($help -)2:port:_ports" && ret=0
   446              ;;
   447          (ps)
   448              _arguments \
   449                  $opts_help \
   450                  "($help -a --all)"{-a,--all}"[Show all containers]" \
   451                  "($help)--before=-[Show only container created before...]:containers:__docker_containers" \
   452                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   453                  "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
   454                  "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \
   455                  "($help)--no-trunc[Do not truncate output]" \
   456                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   457                  "($help -s --size)"{-s,--size}"[Display total file sizes]" \
   458                  "($help)--since=-[Show only containers created since...]:containers:__docker_containers" && ret=0
   459              ;;
   460          (pull)
   461              _arguments \
   462                  $opts_help \
   463                  "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
   464                  "($help -):name:__docker_search" && ret=0
   465              ;;
   466          (push)
   467              _arguments \
   468                  $opts_help \
   469                  "($help -): :__docker_images" && ret=0
   470              ;;
   471          (rename)
   472              _arguments \
   473                  $opts_help \
   474                  "($help -):old name:__docker_containers" \
   475                  "($help -):new name: " && ret=0
   476              ;;
   477          (restart|stop)
   478              _arguments \
   479                  $opts_help \
   480                  "($help -t --time=-)"{-t,--time=-}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \
   481                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   482              ;;
   483          (rm)
   484              _arguments \
   485                  $opts_help \
   486                  "($help -f --force)"{-f,--force}"[Force removal]" \
   487                  "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
   488                  "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
   489                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   490              ;;
   491          (rmi)
   492              _arguments \
   493                  $opts_help \
   494                  "($help -f --force)"{-f,--force}"[Force removal]" \
   495                  "($help)--no-prune[Do not delete untagged parents]" \
   496                  "($help -)*: :__docker_images" && ret=0
   497              ;;
   498          (run)
   499              _arguments \
   500                  $opts_help \
   501                  $opts_cpumem \
   502                  $opts_create \
   503                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   504                  "($help)--rm[Remove intermediate containers when it exits]" \
   505                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   506                  "($help)--stop-signal[Signal to kill a container]" \
   507                  "($help -): :__docker_images" \
   508                  "($help -):command: _command_names -e" \
   509                  "($help -)*::arguments: _normal" && ret=0
   510  
   511              case $state in
   512                  (link)
   513                      if compset -P "*:"; then
   514                          _wanted alias expl "Alias" compadd -E "" && ret=0
   515                      else
   516                          __docker_runningcontainers -qS ":" && ret=0
   517                      fi
   518                      ;;
   519              esac
   520  
   521              ;;
   522          (save)
   523              _arguments \
   524                  $opts_help \
   525                  "($help -o --output)"{-o,--output=-}"[Write to file]:file:_files" \
   526                  "($help -)*: :__docker_images" && ret=0
   527              ;;
   528          (search)
   529              _arguments \
   530                  $opts_help \
   531                  "($help)--automated[Only show automated builds]" \
   532                  "($help)--no-trunc[Do not truncate output]" \
   533                  "($help -s --stars)"{-s,--stars=-}"[Only display with at least X stars]:stars:(0 10 100 1000)" \
   534                  "($help -):term: " && ret=0
   535              ;;
   536          (start)
   537              _arguments \
   538                  $opts_help \
   539                  "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
   540                  "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
   541                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   542              ;;
   543          (stats)
   544              _arguments \
   545                  $opts_help \
   546                  "($help)--no-stream[Disable streaming stats and only pull the first result]" \
   547                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   548              ;;
   549          (tag)
   550              _arguments \
   551                  $opts_help \
   552                  "($help -f --force)"{-f,--force}"[force]"\
   553                  "($help -):source:__docker_images"\
   554                  "($help -):destination:__docker_repositories_with_tags" && ret=0
   555              ;;
   556          (top)
   557              _arguments \
   558                  $opts_help \
   559                  "($help -)1:containers:__docker_runningcontainers" \
   560                  "($help -)*:: :->ps-arguments" && ret=0
   561              case $state in
   562                  (ps-arguments)
   563                      _ps && ret=0
   564                      ;;
   565              esac
   566  
   567              ;;
   568          (wait)
   569              _arguments \
   570                  $opts_help \
   571                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   572              ;;
   573          (help)
   574              _arguments ":subcommand:__docker_commands" && ret=0
   575              ;;
   576      esac
   577  
   578      return ret
   579  }
   580  
   581  _docker() {
   582      # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
   583      # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
   584      if [[ $service != docker ]]; then
   585          _call_function - _$service
   586          return
   587      fi
   588  
   589      local curcontext="$curcontext" state line help="-h --help"
   590      integer ret=1
   591      typeset -A opt_args
   592  
   593      _arguments -C \
   594          "(: -)"{-h,--help}"[Print usage]" \
   595          "($help)--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: " \
   596          "($help -b --bridge)"{-b,--bridge=-}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
   597          "($help)--bip=-[Specify network bridge IP]" \
   598          "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
   599          "($help -d --daeamon)"{-d,--daemon}"[Enable daemon mode]" \
   600          "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
   601          "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
   602          "($help)*--dns=-[DNS server to use]:DNS: " \
   603          "($help)*--dns-search=-[DNS search domains to use]:DNS search: " \
   604          "($help)*--dns-opt=-[DNS options to use]:DNS option: " \
   605          "($help)*--default-ulimit=-[Set default ulimit settings for containers]:ulimit: " \
   606          "($help -e --exec-driver)"{-e,--exec-driver=-}"[Exec driver to use]:driver:(native lxc windows)" \
   607          "($help)*--exec-opt=-[Set exec driver options]:exec driver options: " \
   608          "($help)--exec-root=-[Root of the Docker execdriver]:path:_directories" \
   609          "($help)--fixed-cidr=-[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
   610          "($help)--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
   611          "($help -G --group)"{-G,--group=-}"[Group for the unix socket]:group:_groups" \
   612          "($help -g --graph)"{-g,--graph=-}"[Root of the Docker runtime]:path:_directories" \
   613          "($help -H --host)"{-H,--host=-}"[tcp://host:port to bind/connect to]:host: " \
   614          "($help)--icc[Enable inter-container communication]" \
   615          "($help)*--insecure-registry=-[Enable insecure registry communication]:registry: " \
   616          "($help)--ip=-[Default IP when binding container ports]" \
   617          "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
   618          "($help)--ip-masq[Enable IP masquerading]" \
   619          "($help)--iptables[Enable addition of iptables rules]" \
   620          "($help)--ipv6[Enable IPv6 networking]" \
   621          "($help -l --log-level)"{-l,--log-level=-}"[Set the logging level]:level:(debug info warn error fatal)" \
   622          "($help)*--label=-[Set key=value labels to the daemon]:label: " \
   623          "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs none)" \
   624          "($help)*--log-opt=-[Log driver specific options]:log driver options: " \
   625          "($help)--mtu=-[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \
   626          "($help -p --pidfile)"{-p,--pidfile=-}"[Path to use for daemon PID file]:PID file:_files" \
   627          "($help)*--registry-mirror=-[Preferred Docker registry mirror]:registry mirror: " \
   628          "($help -s --storage-driver)"{-s,--storage-driver=-}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \
   629          "($help)--selinux-enabled[Enable selinux support]" \
   630          "($help)*--storage-opt=-[Set storage driver options]:storage driver options: " \
   631          "($help)--tls[Use TLS]" \
   632          "($help)--tlscacert=-[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
   633          "($help)--tlscert=-[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
   634          "($help)--tlskey=-[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
   635          "($help)--tlsverify[Use TLS and verify the remote]" \
   636          "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
   637          "($help -v --version)"{-v,--version}"[Print version information and quit]" \
   638          "($help -): :->command" \
   639          "($help -)*:: :->option-or-argument" && ret=0
   640  
   641      local host=${opt_args[-H]}${opt_args[--host]}
   642      local docker_options=${host:+--host $host}
   643  
   644      case $state in
   645          (command)
   646              __docker_commands && ret=0
   647              ;;
   648          (option-or-argument)
   649              curcontext=${curcontext%:*:*}:docker-$words[1]:
   650              __docker_subcommand && ret=0
   651              ;;
   652      esac
   653  
   654      return ret
   655  }
   656  
   657  _docker "$@"
   658  
   659  # Local Variables:
   660  # mode: Shell-Script
   661  # sh-indentation: 4
   662  # indent-tabs-mode: nil
   663  # sh-basic-offset: 4
   664  # End:
   665  # vim: ft=zsh sw=4 ts=4 et