github.com/iaintshine/docker@v1.8.2/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-search=-[Set custom DNS search domains]:dns domains: "
   231          "($help)*"{-e,--env=-}"[Set environment variables]:environment variable: "
   232          "($help)--entrypoint=-[Overwrite the default entrypoint of the image]:entry point: "
   233          "($help)*--env-file=-[Read environment variables from a file]:environment file:_files"
   234          "($help)*--expose=-[Expose a port from the container without publishing it]: "
   235          "($help)*--group-add=-[Add additional groups to run as]:group:_groups"
   236          "($help -h --hostname)"{-h,--hostname=-}"[Container host name]:hostname:_hosts"
   237          "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
   238          "($help)--ipc=-[IPC namespace to use]:IPC namespace: "
   239          "($help)*--link=-[Add link to another container]:link:->link"
   240          "($help)*"{-l,--label=-}"[Set meta data on a container]:label: "
   241          "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd none)"
   242          "($help)*--log-opt=-[Log driver specific options]:log driver options: "
   243          "($help)*--lxc-conf=-[Add custom lxc options]:lxc options: "
   244          "($help)--mac-address=-[Container MAC address]:MAC address: "
   245          "($help)--name=-[Container name]:name: "
   246          "($help)--net=-[Network mode]:network mode:(bridge none container host)"
   247          "($help)--oom-kill-disable[Disable OOM Killer]"
   248          "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
   249          "($help)*"{-p,--publish=-}"[Expose a container's port to the host]:port:_ports"
   250          "($help)--pid=-[PID namespace to use]:PID: "
   251          "($help)--privileged[Give extended privileges to this container]"
   252          "($help)--read-only[Mount the container's root filesystem as read only]"
   253          "($help)--restart=-[Restart policy]:restart policy:(no on-failure always)"
   254          "($help)*--security-opt=-[Security options]:security option: "
   255          "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
   256          "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users"
   257          "($help)*--ulimit=-[ulimit options]:ulimit: "
   258          "($help)*-v[Bind mount a volume]:volume: "
   259          "($help)*--volumes-from=-[Mount volumes from the specified container]:volume: "
   260          "($help -w --workdir)"{-w,--workdir=-}"[Working directory inside the container]:directory:_directories"
   261      )
   262  
   263      case "$words[1]" in
   264          (attach)
   265              _arguments \
   266                  $opts_help \
   267                  "($help)--no-stdin[Do not attach stdin]" \
   268                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   269                  "($help -):containers:__docker_runningcontainers" && ret=0
   270              ;;
   271          (build)
   272              _arguments \
   273                  $opts_help \
   274                  $opts_cpumem \
   275                  "($help -f --file)"{-f,--file=-}"[Name of the Dockerfile]:Dockerfile:_files" \
   276                  "($help)--force-rm[Always remove intermediate containers]" \
   277                  "($help)--no-cache[Do not use cache when building the image]" \
   278                  "($help)--pull[Attempt to pull a newer version of the image]" \
   279                  "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
   280                  "($help)--rm[Remove intermediate containers after a successful build]" \
   281                  "($help -t --tag)"{-t,--tag=-}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
   282                  "($help -):path or URL:_directories" && ret=0
   283              ;;
   284          (commit)
   285              _arguments \
   286                  $opts_help \
   287                  "($help -a --author)"{-a,--author=-}"[Author]:author: " \
   288                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   289                  "($help -m --message)"{-m,--message=-}"[Commit message]:message: " \
   290                  "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
   291                  "($help -):container:__docker_containers" \
   292                  "($help -): :__docker_repositories_with_tags" && ret=0
   293              ;;
   294          (cp)
   295              _arguments \
   296                  $opts_help \
   297                  "($help -)1:container:->container" \
   298                  "($help -)2:hostpath:_files" && ret=0
   299              case $state in
   300                  (container)
   301                      if compset -P "*:"; then
   302                          _files && ret=0
   303                      else
   304                          __docker_containers -qS ":" && ret=0
   305                      fi
   306                      ;;
   307              esac
   308              ;;
   309          (create)
   310              _arguments \
   311                  $opts_help \
   312                  $opts_cpumem \
   313                  $opts_create \
   314                  "($help -): :__docker_images" \
   315                  "($help -):command: _command_names -e" \
   316                  "($help -)*::arguments: _normal" && ret=0
   317  
   318              case $state in
   319                  (link)
   320                      if compset -P "*:"; then
   321                          _wanted alias expl "Alias" compadd -E "" && ret=0
   322                      else
   323                          __docker_runningcontainers -qS ":" && ret=0
   324                      fi
   325                      ;;
   326              esac
   327  
   328              ;;
   329          (diff)
   330              _arguments \
   331                  $opts_help \
   332                  "($help -)*:containers:__docker_containers" && ret=0
   333              ;;
   334          (events)
   335              _arguments \
   336                  $opts_help \
   337                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   338                  "($help)--since=-[Events created since this timestamp]:timestamp: " \
   339                  "($help)--until=-[Events created until this timestamp]:timestamp: " && ret=0
   340              ;;
   341          (exec)
   342              local state
   343              _arguments \
   344                  $opts_help \
   345                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   346                  "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
   347                  "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
   348                  "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users" \
   349                  "($help -):containers:__docker_runningcontainers" \
   350                  "($help -)*::command:->anycommand" && ret=0
   351  
   352              case $state in
   353                  (anycommand)
   354                      shift 1 words
   355                      (( CURRENT-- ))
   356                      _normal && ret=0
   357                      ;;
   358              esac
   359              ;;
   360          (export)
   361              _arguments \
   362                  $opts_help \
   363                  "($help -o --output)"{-o,--output=-}"[Write to a file, instead of stdout]:output file:_files" \
   364                  "($help -)*:containers:__docker_containers" && ret=0
   365              ;;
   366          (history)
   367              _arguments \
   368                  $opts_help \
   369                  "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
   370                  "($help)--no-trunc[Do not truncate output]" \
   371                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   372                  "($help -)*: :__docker_images" && ret=0
   373              ;;
   374          (images)
   375              _arguments \
   376                  $opts_help \
   377                  "($help -a --all)"{-a,--all}"[Show all images]" \
   378                  "($help)--digest[Show digests]" \
   379                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   380                  "($help)--no-trunc[Do not truncate output]" \
   381                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   382                  "($help -): :__docker_repositories" && ret=0
   383              ;;
   384          (import)
   385              _arguments \
   386                  $opts_help \
   387                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   388                  "($help -):URL:(- http:// file://)" \
   389                  "($help -): :__docker_repositories_with_tags" && ret=0
   390              ;;
   391          (info|version)
   392              _arguments \
   393                  $opts_help && ret=0
   394              ;;
   395          (inspect)
   396              _arguments \
   397                  $opts_help \
   398                  "($help -f --format=-)"{-f,--format=-}"[Format the output using the given go template]:template: " \
   399                  "($help)--type=-[Return JSON for specified type]:type:(image container)" \
   400                  "($help -)*:containers:__docker_containers" && ret=0
   401              ;;
   402          (kill)
   403              _arguments \
   404                  $opts_help \
   405                  "($help -s --signal)"{-s,--signal=-}"[Signal to send]:signal:_signals" \
   406                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   407              ;;
   408          (load)
   409              _arguments \
   410                  $opts_help \
   411                  "($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
   412              ;;
   413          (login)
   414              _arguments \
   415                  $opts_help \
   416                  "($help -e --email)"{-e,--email=-}"[Email]:email: " \
   417                  "($help -p --password)"{-p,--password=-}"[Password]:password: " \
   418                  "($help -u --user)"{-u,--user=-}"[Username]:username: " \
   419                  "($help -)1:server: " && ret=0
   420              ;;
   421          (logout)
   422              _arguments \
   423                  $opts_help \
   424                  "($help -)1:server: " && ret=0
   425              ;;
   426          (logs)
   427              _arguments \
   428                  $opts_help \
   429                  "($help -f --follow)"{-f,--follow}"[Follow log output]" \
   430                  "($help -s --since)"{-s,--since=-}"[Show logs since this timestamp]:timestamp: " \
   431                  "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
   432                  "($help)--tail=-[Output the last K lines]:lines:(1 10 20 50 all)" \
   433                  "($help -)*:containers:__docker_containers" && ret=0
   434              ;;
   435          (pause|unpause)
   436              _arguments \
   437                  $opts_help \
   438                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   439              ;;
   440          (port)
   441              _arguments \
   442                  $opts_help \
   443                  "($help -)1:containers:__docker_runningcontainers" \
   444                  "($help -)2:port:_ports" && ret=0
   445              ;;
   446          (ps)
   447              _arguments \
   448                  $opts_help \
   449                  "($help -a --all)"{-a,--all}"[Show all containers]" \
   450                  "($help)--before=-[Show only container created before...]:containers:__docker_containers" \
   451                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   452                  "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
   453                  "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \
   454                  "($help)--no-trunc[Do not truncate output]" \
   455                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   456                  "($help -s --size)"{-s,--size}"[Display total file sizes]" \
   457                  "($help)--since=-[Show only containers created since...]:containers:__docker_containers" && ret=0
   458              ;;
   459          (pull)
   460              _arguments \
   461                  $opts_help \
   462                  "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
   463                  "($help -):name:__docker_search" && ret=0
   464              ;;
   465          (push)
   466              _arguments \
   467                  $opts_help \
   468                  "($help -): :__docker_images" && ret=0
   469              ;;
   470          (rename)
   471              _arguments \
   472                  $opts_help \
   473                  "($help -):old name:__docker_containers" \
   474                  "($help -):new name: " && ret=0
   475              ;;
   476          (restart|stop)
   477              _arguments \
   478                  $opts_help \
   479                  "($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)" \
   480                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   481              ;;
   482          (rm)
   483              _arguments \
   484                  $opts_help \
   485                  "($help -f --force)"{-f,--force}"[Force removal]" \
   486                  "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
   487                  "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
   488                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   489              ;;
   490          (rmi)
   491              _arguments \
   492                  $opts_help \
   493                  "($help -f --force)"{-f,--force}"[Force removal]" \
   494                  "($help)--no-prune[Do not delete untagged parents]" \
   495                  "($help -)*: :__docker_images" && ret=0
   496              ;;
   497          (run)
   498              _arguments \
   499                  $opts_help \
   500                  $opts_cpumem \
   501                  $opts_create \
   502                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   503                  "($help)--rm[Remove intermediate containers when it exits]" \
   504                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   505                  "($help -): :__docker_images" \
   506                  "($help -):command: _command_names -e" \
   507                  "($help -)*::arguments: _normal" && ret=0
   508  
   509              case $state in
   510                  (link)
   511                      if compset -P "*:"; then
   512                          _wanted alias expl "Alias" compadd -E "" && ret=0
   513                      else
   514                          __docker_runningcontainers -qS ":" && ret=0
   515                      fi
   516                      ;;
   517              esac
   518  
   519              ;;
   520          (save)
   521              _arguments \
   522                  $opts_help \
   523                  "($help -o --output)"{-o,--output=-}"[Write to file]:file:_files" \
   524                  "($help -)*: :__docker_images" && ret=0
   525              ;;
   526          (search)
   527              _arguments \
   528                  $opts_help \
   529                  "($help)--automated[Only show automated builds]" \
   530                  "($help)--no-trunc[Do not truncate output]" \
   531                  "($help -s --stars)"{-s,--stars=-}"[Only display with at least X stars]:stars:(0 10 100 1000)" \
   532                  "($help -):term: " && ret=0
   533              ;;
   534          (start)
   535              _arguments \
   536                  $opts_help \
   537                  "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
   538                  "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
   539                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   540              ;;
   541          (stats)
   542              _arguments \
   543                  $opts_help \
   544                  "($help)--no-stream[Disable streaming stats and only pull the first result]" \
   545                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   546              ;;
   547          (tag)
   548              _arguments \
   549                  $opts_help \
   550                  "($help -f --force)"{-f,--force}"[force]"\
   551                  "($help -):source:__docker_images"\
   552                  "($help -):destination:__docker_repositories_with_tags" && ret=0
   553              ;;
   554          (top)
   555              _arguments \
   556                  $opts_help \
   557                  "($help -)1:containers:__docker_runningcontainers" \
   558                  "($help -)*:: :->ps-arguments" && ret=0
   559              case $state in
   560                  (ps-arguments)
   561                      _ps && ret=0
   562                      ;;
   563              esac
   564  
   565              ;;
   566          (wait)
   567              _arguments \
   568                  $opts_help \
   569                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   570              ;;
   571          (help)
   572              _arguments ":subcommand:__docker_commands" && ret=0
   573              ;;
   574      esac
   575  
   576      return ret
   577  }
   578  
   579  _docker() {
   580      # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
   581      # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
   582      if [[ $service != docker ]]; then
   583          _call_function - _$service
   584          return
   585      fi
   586  
   587      local curcontext="$curcontext" state line help="-h --help"
   588      integer ret=1
   589      typeset -A opt_args
   590  
   591      _arguments -C \
   592          "(: -)"{-h,--help}"[Print usage]" \
   593          "($help)--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: " \
   594          "($help -b --bridge)"{-b,--bridge=-}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
   595          "($help)--bip=-[Specify network bridge IP]" \
   596          "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
   597          "($help -d --daeamon)"{-d,--daemon}"[Enable daemon mode]" \
   598          "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
   599          "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
   600          "($help)*--dns=-[DNS server to use]:DNS: " \
   601          "($help)*--dns-search=-[DNS search domains to use]" \
   602          "($help)*--default-ulimit=-[Set default ulimit settings for containers]:ulimit: " \
   603          "($help -e --exec-driver)"{-e,--exec-driver=-}"[Exec driver to use]:driver:(native lxc windows)" \
   604          "($help)*--exec-opt=-[Set exec driver options]:exec driver options: " \
   605          "($help)--exec-root=-[Root of the Docker execdriver]:path:_directories" \
   606          "($help)--fixed-cidr=-[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
   607          "($help)--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
   608          "($help -G --group)"{-G,--group=-}"[Group for the unix socket]:group:_groups" \
   609          "($help -g --graph)"{-g,--graph=-}"[Root of the Docker runtime]:path:_directories" \
   610          "($help -H --host)"{-H,--host=-}"[tcp://host:port to bind/connect to]:host: " \
   611          "($help)--icc[Enable inter-container communication]" \
   612          "($help)*--insecure-registry=-[Enable insecure registry communication]:registry: " \
   613          "($help)--ip=-[Default IP when binding container ports]" \
   614          "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
   615          "($help)--ip-masq[Enable IP masquerading]" \
   616          "($help)--iptables[Enable addition of iptables rules]" \
   617          "($help)--ipv6[Enable IPv6 networking]" \
   618          "($help -l --log-level)"{-l,--log-level=-}"[Set the logging level]:level:(debug info warn error fatal)" \
   619          "($help)*--label=-[Set key=value labels to the daemon]:label: " \
   620          "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd none)" \
   621          "($help)*--log-opt=-[Log driver specific options]:log driver options: " \
   622          "($help)--mtu=-[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \
   623          "($help -p --pidfile)"{-p,--pidfile=-}"[Path to use for daemon PID file]:PID file:_files" \
   624          "($help)*--registry-mirror=-[Preferred Docker registry mirror]:registry mirror: " \
   625          "($help -s --storage-driver)"{-s,--storage-driver=-}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \
   626          "($help)--selinux-enabled[Enable selinux support]" \
   627          "($help)*--storage-opt=-[Set storage driver options]:storage driver options: " \
   628          "($help)--tls[Use TLS]" \
   629          "($help)--tlscacert=-[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
   630          "($help)--tlscert=-[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
   631          "($help)--tlskey=-[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
   632          "($help)--tlsverify[Use TLS and verify the remote]" \
   633          "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
   634          "($help -v --version)"{-v,--version}"[Print version information and quit]" \
   635          "($help -): :->command" \
   636          "($help -)*:: :->option-or-argument" && ret=0
   637  
   638      local host=${opt_args[-H]}${opt_args[--host]}
   639      local docker_options=${host:+--host $host}
   640  
   641      case $state in
   642          (command)
   643              __docker_commands && ret=0
   644              ;;
   645          (option-or-argument)
   646              curcontext=${curcontext%:*:*}:docker-$words[1]:
   647              __docker_subcommand && ret=0
   648              ;;
   649      esac
   650  
   651      return ret
   652  }
   653  
   654  _docker "$@"
   655  
   656  # Local Variables:
   657  # mode: Shell-Script
   658  # sh-indentation: 4
   659  # indent-tabs-mode: nil
   660  # sh-basic-offset: 4
   661  # End:
   662  # vim: ft=zsh sw=4 ts=4 et