github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/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 # Short-option stacking can be enabled with: 42 # zstyle ':completion:*:*:docker:*' option-stacking yes 43 # zstyle ':completion:*:*:docker-*:*' option-stacking yes 44 __docker_arguments() { 45 if zstyle -t ":completion:${curcontext}:" option-stacking; then 46 print -- -s 47 fi 48 } 49 50 __docker_get_containers() { 51 [[ $PREFIX = -* ]] && return 1 52 integer ret=1 53 local kind 54 declare -a running stopped lines args 55 56 kind=$1 57 shift 58 [[ $kind = (stopped|all) ]] && args=($args -a) 59 60 lines=(${(f)"$(_call_program commands docker $docker_options ps --no-trunc $args)"}) 61 62 # Parse header line to find columns 63 local i=1 j=1 k header=${lines[1]} 64 declare -A begin end 65 while (( j < ${#header} - 1 )); do 66 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 67 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 68 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 69 begin[${header[$i,$((j-1))]}]=$i 70 end[${header[$i,$((j-1))]}]=$k 71 done 72 end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line 73 lines=(${lines[2,-1]}) 74 75 # Container ID 76 local line 77 local s 78 for line in $lines; do 79 s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" 80 s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 81 s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" 82 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 83 stopped=($stopped $s) 84 else 85 running=($running $s) 86 fi 87 done 88 89 # Names: we only display the one without slash. All other names 90 # are generated and may clutter the completion. However, with 91 # Swarm, all names may be prefixed by the swarm node name. 92 local -a names 93 for line in $lines; do 94 names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) 95 # First step: find a common prefix and strip it (swarm node case) 96 (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} 97 # Second step: only keep the first name without a / 98 s=${${names:#*/*}[1]} 99 # If no name, well give up. 100 (( $#s != 0 )) || continue 101 s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 102 s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" 103 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 104 stopped=($stopped $s) 105 else 106 running=($running $s) 107 fi 108 done 109 110 [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 111 [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 112 return ret 113 } 114 115 __docker_stoppedcontainers() { 116 [[ $PREFIX = -* ]] && return 1 117 __docker_get_containers stopped "$@" 118 } 119 120 __docker_runningcontainers() { 121 [[ $PREFIX = -* ]] && return 1 122 __docker_get_containers running "$@" 123 } 124 125 __docker_containers() { 126 [[ $PREFIX = -* ]] && return 1 127 __docker_get_containers all "$@" 128 } 129 130 __docker_images() { 131 [[ $PREFIX = -* ]] && return 1 132 integer ret=1 133 declare -a images 134 images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) 135 _describe -t docker-images "images" images && ret=0 136 __docker_repositories_with_tags && ret=0 137 return ret 138 } 139 140 __docker_repositories() { 141 [[ $PREFIX = -* ]] && return 1 142 declare -a repos 143 repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]}) 144 repos=(${repos#<none>}) 145 _describe -t docker-repos "repositories" repos 146 } 147 148 __docker_repositories_with_tags() { 149 [[ $PREFIX = -* ]] && return 1 150 integer ret=1 151 declare -a repos onlyrepos matched 152 declare m 153 repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *}) 154 repos=(${${repos%:::<none>}#<none>}) 155 # Check if we have a prefix-match for the current prefix. 156 onlyrepos=(${repos%::*}) 157 for m in $onlyrepos; do 158 [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { 159 # Yes, complete with tags 160 repos=(${${repos/:::/:}/:/\\:}) 161 _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 162 return ret 163 } 164 done 165 # No, only complete repositories 166 onlyrepos=(${${repos%:::*}/:/\\:}) 167 _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 168 169 return ret 170 } 171 172 __docker_search() { 173 [[ $PREFIX = -* ]] && return 1 174 local cache_policy 175 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 176 if [[ -z "$cache_policy" ]]; then 177 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 178 fi 179 180 local searchterm cachename 181 searchterm="${words[$CURRENT]%/}" 182 cachename=_docker-search-$searchterm 183 184 local expl 185 local -a result 186 if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ 187 && ! _retrieve_cache ${cachename#_}; then 188 _message "Searching for ${searchterm}..." 189 result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]}) 190 _store_cache ${cachename#_} result 191 fi 192 _wanted dockersearch expl 'available images' compadd -a result 193 } 194 195 __docker_get_log_options() { 196 [[ $PREFIX = -* ]] && return 1 197 198 integer ret=1 199 local log_driver=${opt_args[--log-driver]:-"all"} 200 local -a awslogs_options fluentd_options gelf_options journald_options json_file_options syslog_options splunk_options 201 202 awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") 203 fluentd_options=("env" "fluentd-address" "labels" "tag") 204 gelf_options=("env" "gelf-address" "labels" "tag") 205 journald_options=("env" "labels") 206 json_file_options=("env" "labels" "max-file" "max-size") 207 syslog_options=("syslog-address" "syslog-facility" "tag") 208 splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "tag") 209 210 [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 211 [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 212 [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 213 [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 214 [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 215 [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 216 [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 217 218 return ret 219 } 220 221 __docker_log_options() { 222 [[ $PREFIX = -* ]] && return 1 223 integer ret=1 224 225 if compset -P '*='; then 226 _message 'value' && ret=0 227 else 228 __docker_get_log_options -qS "=" && ret=0 229 fi 230 231 return ret 232 } 233 234 __docker_networks() { 235 [[ $PREFIX = -* ]] && return 1 236 integer ret=1 237 declare -a lines networks 238 239 lines=(${(f)"$(_call_program commands docker $docker_options network ls)"}) 240 241 # Parse header line to find columns 242 local i=1 j=1 k header=${lines[1]} 243 declare -A begin end 244 while (( j < ${#header} - 1 )); do 245 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 246 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 247 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 248 begin[${header[$i,$((j-1))]}]=$i 249 end[${header[$i,$((j-1))]}]=$k 250 done 251 end[${header[$i,$((j-1))]}]=-1 252 lines=(${lines[2,-1]}) 253 254 # Network ID 255 local line s 256 for line in $lines; do 257 s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" 258 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 259 networks=($networks $s) 260 done 261 262 # Names 263 for line in $lines; do 264 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 265 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 266 networks=($networks $s) 267 done 268 269 _describe -t networks-list "networks" networks && ret=0 270 return ret 271 } 272 273 __docker_network_commands() { 274 local -a _docker_network_subcommands 275 _docker_network_subcommands=( 276 "connect:onnects a container to a network" 277 "create:Creates a new network with a name specified by the user" 278 "disconnect:Disconnects a container from a network" 279 "inspect:Displays detailed information on a network" 280 "ls:Lists all the networks created by the user" 281 "rm:Deletes one or more networks" 282 ) 283 _describe -t docker-network-commands "docker network command" _docker_network_subcommands 284 } 285 286 __docker_network_subcommand() { 287 local -a _command_args opts_help 288 local expl help="--help" 289 integer ret=1 290 291 opts_help=("(: -)--help[Print usage]") 292 293 case "$words[1]" in 294 (connect|disconnect) 295 _arguments $(__docker_arguments) \ 296 $opts_help \ 297 "($help -)1:network:__docker_networks" \ 298 "($help -)2:containers:__docker_runningcontainers" && ret=0 299 ;; 300 (create) 301 _arguments $(__docker_arguments) -A '-*' \ 302 $opts_help \ 303 "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ 304 "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ 305 "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ 306 "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ 307 "($help)*--gateway=[ipv4 or ipv6 Gateway for the master subnet]:IP: " \ 308 "($help)*--aux-address[Auxiliary ipv4 or ipv6 addresses used by network driver]:key=IP: " \ 309 "($help)*"{-o=,--opt=}"[Set driver specific options]:key=value: " \ 310 "($help -)1:Network Name: " && ret=0 311 ;; 312 (inspect) 313 _arguments $(__docker_arguments) \ 314 $opts_help \ 315 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 316 "($help -)*:network:__docker_networks" && ret=0 317 ;; 318 (ls) 319 _arguments $(__docker_arguments) \ 320 $opts_help \ 321 "($help)--no-trunc[Do not truncate the output]" \ 322 "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 323 ;; 324 (rm) 325 _arguments $(__docker_arguments) \ 326 $opts_help \ 327 "($help -)*:network:__docker_networks" && ret=0 328 ;; 329 (help) 330 _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 331 ;; 332 esac 333 334 return ret 335 } 336 337 __docker_volumes() { 338 [[ $PREFIX = -* ]] && return 1 339 integer ret=1 340 declare -a lines volumes 341 342 lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"}) 343 344 # Parse header line to find columns 345 local i=1 j=1 k header=${lines[1]} 346 declare -A begin end 347 while (( j < ${#header} - 1 )); do 348 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 349 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 350 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 351 begin[${header[$i,$((j-1))]}]=$i 352 end[${header[$i,$((j-1))]}]=$k 353 done 354 end[${header[$i,$((j-1))]}]=-1 355 lines=(${lines[2,-1]}) 356 357 # Names 358 local line s 359 for line in $lines; do 360 s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" 361 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 362 volumes=($volumes $s) 363 done 364 365 _describe -t volumes-list "volumes" volumes && ret=0 366 return ret 367 } 368 369 __docker_volume_commands() { 370 local -a _docker_volume_subcommands 371 _docker_volume_subcommands=( 372 "create:Create a volume" 373 "inspect:Return low-level information on a volume" 374 "ls:List volumes" 375 "rm:Remove a volume" 376 ) 377 _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands 378 } 379 380 __docker_volume_subcommand() { 381 local -a _command_args opts_help 382 local expl help="--help" 383 integer ret=1 384 385 opts_help=("(: -)--help[Print usage]") 386 387 case "$words[1]" in 388 (create) 389 _arguments $(__docker_arguments) \ 390 $opts_help \ 391 "($help -d --driver)"{-d=,--driver=}"[Specify volume driver name]:Driver name:(local)" \ 392 "($help)--name=[Specify volume name]" \ 393 "($help)*"{-o=,--opt=}"[Set driver specific options]:Driver option: " && ret=0 394 ;; 395 (inspect) 396 _arguments $(__docker_arguments) \ 397 $opts_help \ 398 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 399 "($help -)1:volume:__docker_volumes" && ret=0 400 ;; 401 (ls) 402 _arguments $(__docker_arguments) \ 403 $opts_help \ 404 "($help)*"{-f=,--filter=}"[Provide filter values (i.e. 'dangling=true')]:filter: " \ 405 "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 406 ;; 407 (rm) 408 _arguments $(__docker_arguments) \ 409 $opts_help \ 410 "($help -):volume:__docker_volumes" && ret=0 411 ;; 412 (help) 413 _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 414 ;; 415 esac 416 417 return ret 418 } 419 420 __docker_caching_policy() { 421 oldp=( "$1"(Nmh+1) ) # 1 hour 422 (( $#oldp )) 423 } 424 425 __docker_commands() { 426 local cache_policy 427 428 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 429 if [[ -z "$cache_policy" ]]; then 430 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 431 fi 432 433 if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ 434 && ! _retrieve_cache docker_subcommands; 435 then 436 local -a lines 437 lines=(${(f)"$(_call_program commands docker 2>&1)"}) 438 _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) 439 _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') 440 (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands 441 fi 442 _describe -t docker-commands "docker command" _docker_subcommands 443 } 444 445 __docker_subcommand() { 446 local -a _command_args opts_help opts_cpumemlimit opts_create 447 local expl help="--help" 448 integer ret=1 449 450 opts_help=("(: -)--help[Print usage]") 451 opts_cpumemlimit=( 452 "($help)--cpu-shares=[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" 453 "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " 454 "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " 455 "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " 456 "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " 457 "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " 458 "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " 459 "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " 460 "($help)*--ulimit=[ulimit options]:ulimit: " 461 ) 462 opts_create=( 463 "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" 464 "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " 465 "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" 466 "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " 467 "($help)*--cap-add=[Add Linux capabilities]:capability: " 468 "($help)*--cap-drop=[Drop Linux capabilities]:capability: " 469 "($help)--cidfile=[Write the container ID to the file]:CID file:_files" 470 "($help)*--device=[Add a host device to the container]:device:_files" 471 "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " 472 "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " 473 "($help)*--dns=[Set custom DNS servers]:DNS server: " 474 "($help)*--dns-opt=[Set custom DNS options]:DNS option: " 475 "($help)*--dns-search=[Set custom DNS search domains]:DNS domains: " 476 "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " 477 "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " 478 "($help)*--env-file=[Read environment variables from a file]:environment file:_files" 479 "($help)*--expose=[Expose a port from the container without publishing it]: " 480 "($help)*--group-add=[Add additional groups to run as]:group:_groups" 481 "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" 482 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" 483 "($help)--ipc=[IPC namespace to use]:IPC namespace: " 484 "($help)--kernel-memory[Kernel memory limit in bytes.]:Memory limit: " 485 "($help)*--link=[Add link to another container]:link:->link" 486 "($help)*"{-l=,--label=}"[Set meta data on a container]:label: " 487 "($help)--log-driver=[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs splunk none)" 488 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" 489 "($help)--mac-address=[Container MAC address]:MAC address: " 490 "($help)--name=[Container name]:name: " 491 "($help)--net=[Connect a container to a network]:network mode:(bridge none container host)" 492 "($help)--oom-kill-disable[Disable OOM Killer]" 493 "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" 494 "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" 495 "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" 496 "($help)--pid=[PID namespace to use]:PID: " 497 "($help)--privileged[Give extended privileges to this container]" 498 "($help)--read-only[Mount the container's root filesystem as read only]" 499 "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" 500 "($help)*--security-opt=[Security options]:security option: " 501 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" 502 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" 503 "($help)--tmpfs[mount tmpfs] " 504 "($help)*-v[Bind mount a volume]:volume: " 505 "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" 506 "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " 507 "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" 508 ) 509 510 case "$words[1]" in 511 (attach) 512 _arguments $(__docker_arguments) \ 513 $opts_help \ 514 "($help)--no-stdin[Do not attach stdin]" \ 515 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 516 "($help -):containers:__docker_runningcontainers" && ret=0 517 ;; 518 (build) 519 _arguments $(__docker_arguments) \ 520 $opts_help \ 521 $opts_cpumemlimit \ 522 "($help)*--build-arg[Set build-time variables]:<varname>=<value>: " \ 523 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ 524 "($help)--force-rm[Always remove intermediate containers]" \ 525 "($help)--no-cache[Do not use cache when building the image]" \ 526 "($help)--pull[Attempt to pull a newer version of the image]" \ 527 "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ 528 "($help)--rm[Remove intermediate containers after a successful build]" \ 529 "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \ 530 "($help -):path or URL:_directories" && ret=0 531 ;; 532 (commit) 533 _arguments $(__docker_arguments) \ 534 $opts_help \ 535 "($help -a --author)"{-a=,--author=}"[Author]:author: " \ 536 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 537 "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ 538 "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ 539 "($help -):container:__docker_containers" \ 540 "($help -): :__docker_repositories_with_tags" && ret=0 541 ;; 542 (cp) 543 _arguments $(__docker_arguments) \ 544 $opts_help \ 545 "($help -)1:container:->container" \ 546 "($help -)2:hostpath:_files" && ret=0 547 case $state in 548 (container) 549 if compset -P "*:"; then 550 _files && ret=0 551 else 552 __docker_containers -qS ":" && ret=0 553 fi 554 ;; 555 esac 556 ;; 557 (create) 558 _arguments $(__docker_arguments) \ 559 $opts_help \ 560 $opts_cpumemlimit \ 561 $opts_create \ 562 "($help -): :__docker_images" \ 563 "($help -):command: _command_names -e" \ 564 "($help -)*::arguments: _normal" && ret=0 565 566 case $state in 567 (link) 568 if compset -P "*:"; then 569 _wanted alias expl "Alias" compadd -E "" && ret=0 570 else 571 __docker_runningcontainers -qS ":" && ret=0 572 fi 573 ;; 574 esac 575 576 ;; 577 (daemon) 578 _arguments $(__docker_arguments) \ 579 $opts_help \ 580 "($help)--api-cors-header=[Set CORS headers in the remote API]:CORS headers: " \ 581 "($help)*--authz-plugin=[Set authorization plugins to load]" \ 582 "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ 583 "($help)--bip=[Specify network bridge IP]" \ 584 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 585 "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ 586 "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ 587 "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ 588 "($help)--cluster-advertise=[Address of the daemon instance to advertise]:Instance to advertise (host\:port): " \ 589 "($help)*--cluster-store-opt=[Set cluster options]:Cluster options:->cluster-store-options" \ 590 "($help)*--dns=[DNS server to use]:DNS: " \ 591 "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ 592 "($help)*--dns-opt=[DNS options to use]:DNS option: " \ 593 "($help)*--default-ulimit=[Set default ulimit settings for containers]:ulimit: " \ 594 "($help)--disable-legacy-registry[Do not contact legacy registries]" \ 595 "($help)*--exec-opt=[Set exec driver options]:exec driver options: " \ 596 "($help)--exec-root=[Root of the Docker execdriver]:path:_directories" \ 597 "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ 598 "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ 599 "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ 600 "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ 601 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 602 "($help)--icc[Enable inter-container communication]" \ 603 "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ 604 "($help)--ip=[Default IP when binding container ports]" \ 605 "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ 606 "($help)--ip-masq[Enable IP masquerading]" \ 607 "($help)--iptables[Enable addition of iptables rules]" \ 608 "($help)--ipv6[Enable IPv6 networking]" \ 609 "($help -l --log-level)"{-l=,--log-level=}"[Set the logging level]:level:(debug info warn error fatal)" \ 610 "($help)*--label=[Set key=value labels to the daemon]:label: " \ 611 "($help)--log-driver=[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs splunk none)" \ 612 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \ 613 "($help)--mtu=[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \ 614 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ 615 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ 616 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \ 617 "($help)--selinux-enabled[Enable selinux support]" \ 618 "($help)*--storage-opt=[Set storage driver options]:storage driver options: " \ 619 "($help)--tls[Use TLS]" \ 620 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 621 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 622 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 623 "($help)--tlsverify[Use TLS and verify the remote]" \ 624 "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0 625 626 case $state in 627 (cluster-store) 628 if compset -P '*://'; then 629 _message 'host:port' && ret=0 630 else 631 store=('consul' 'etcd' 'zk') 632 _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 633 fi 634 ;; 635 (cluster-store-options) 636 if compset -P '*='; then 637 _files && ret=0 638 else 639 opts=('kv.cacertfile' 'kv.certfile' 'kv.keyfile') 640 _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 641 fi 642 ;; 643 esac 644 ;; 645 (diff) 646 _arguments $(__docker_arguments) \ 647 $opts_help \ 648 "($help -)*:containers:__docker_containers" && ret=0 649 ;; 650 (events) 651 _arguments $(__docker_arguments) \ 652 $opts_help \ 653 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 654 "($help)--since=[Events created since this timestamp]:timestamp: " \ 655 "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0 656 ;; 657 (exec) 658 local state 659 _arguments $(__docker_arguments) \ 660 $opts_help \ 661 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 662 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ 663 "($help)--privileged[Give extended Linux capabilities to the command]" \ 664 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ 665 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ 666 "($help -):containers:__docker_runningcontainers" \ 667 "($help -)*::command:->anycommand" && ret=0 668 669 case $state in 670 (anycommand) 671 shift 1 words 672 (( CURRENT-- )) 673 _normal && ret=0 674 ;; 675 esac 676 ;; 677 (export) 678 _arguments $(__docker_arguments) \ 679 $opts_help \ 680 "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ 681 "($help -)*:containers:__docker_containers" && ret=0 682 ;; 683 (history) 684 _arguments $(__docker_arguments) \ 685 $opts_help \ 686 "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ 687 "($help)--no-trunc[Do not truncate output]" \ 688 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 689 "($help -)*: :__docker_images" && ret=0 690 ;; 691 (images) 692 _arguments $(__docker_arguments) \ 693 $opts_help \ 694 "($help -a --all)"{-a,--all}"[Show all images]" \ 695 "($help)--digest[Show digests]" \ 696 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 697 "($help)--no-trunc[Do not truncate output]" \ 698 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 699 "($help -): :__docker_repositories" && ret=0 700 ;; 701 (import) 702 _arguments $(__docker_arguments) \ 703 $opts_help \ 704 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 705 "($help -m --message)"{-m=,--message=}"[Set commit message for imported image]:message: " \ 706 "($help -):URL:(- http:// file://)" \ 707 "($help -): :__docker_repositories_with_tags" && ret=0 708 ;; 709 (info|version) 710 _arguments $(__docker_arguments) \ 711 $opts_help && ret=0 712 ;; 713 (inspect) 714 local state 715 _arguments $(__docker_arguments) \ 716 $opts_help \ 717 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 718 "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ 719 "($help)--type=[Return JSON for specified type]:type:(image container)" \ 720 "($help -)*: :->values" && ret=0 721 722 case $state in 723 (values) 724 if [[ ${words[(r)--type=container]} == --type=container ]]; then 725 __docker_containers && ret=0 726 elif [[ ${words[(r)--type=image]} == --type=image ]]; then 727 __docker_images && ret=0 728 else 729 __docker_images && __docker_containers && ret=0 730 fi 731 ;; 732 esac 733 ;; 734 (kill) 735 _arguments $(__docker_arguments) \ 736 $opts_help \ 737 "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ 738 "($help -)*:containers:__docker_runningcontainers" && ret=0 739 ;; 740 (load) 741 _arguments $(__docker_arguments) \ 742 $opts_help \ 743 "($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 744 ;; 745 (login) 746 _arguments $(__docker_arguments) \ 747 $opts_help \ 748 "($help -e --email)"{-e=,--email=}"[Email]:email: " \ 749 "($help -p --password)"{-p=,--password=}"[Password]:password: " \ 750 "($help -u --user)"{-u=,--user=}"[Username]:username: " \ 751 "($help -)1:server: " && ret=0 752 ;; 753 (logout) 754 _arguments $(__docker_arguments) \ 755 $opts_help \ 756 "($help -)1:server: " && ret=0 757 ;; 758 (logs) 759 _arguments $(__docker_arguments) \ 760 $opts_help \ 761 "($help -f --follow)"{-f,--follow}"[Follow log output]" \ 762 "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ 763 "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ 764 "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ 765 "($help -)*:containers:__docker_containers" && ret=0 766 ;; 767 (network) 768 local curcontext="$curcontext" state 769 _arguments $(__docker_arguments) \ 770 $opts_help \ 771 "($help -): :->command" \ 772 "($help -)*:: :->option-or-argument" && ret=0 773 774 case $state in 775 (command) 776 __docker_network_commands && ret=0 777 ;; 778 (option-or-argument) 779 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 780 __docker_network_subcommand && ret=0 781 ;; 782 esac 783 ;; 784 (pause|unpause) 785 _arguments $(__docker_arguments) \ 786 $opts_help \ 787 "($help -)*:containers:__docker_runningcontainers" && ret=0 788 ;; 789 (port) 790 _arguments $(__docker_arguments) \ 791 $opts_help \ 792 "($help -)1:containers:__docker_runningcontainers" \ 793 "($help -)2:port:_ports" && ret=0 794 ;; 795 (ps) 796 _arguments $(__docker_arguments) \ 797 $opts_help \ 798 "($help -a --all)"{-a,--all}"[Show all containers]" \ 799 "($help)--before=[Show only container created before...]:containers:__docker_containers" \ 800 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 801 "($help)--format[Pretty-print containers using a Go template]:format: " \ 802 "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ 803 "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \ 804 "($help)--no-trunc[Do not truncate output]" \ 805 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 806 "($help -s --size)"{-s,--size}"[Display total file sizes]" \ 807 "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0 808 ;; 809 (pull) 810 _arguments $(__docker_arguments) \ 811 $opts_help \ 812 "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ 813 "($help -):name:__docker_search" && ret=0 814 ;; 815 (push) 816 _arguments $(__docker_arguments) \ 817 $opts_help \ 818 "($help -): :__docker_images" && ret=0 819 ;; 820 (rename) 821 _arguments $(__docker_arguments) \ 822 $opts_help \ 823 "($help -):old name:__docker_containers" \ 824 "($help -):new name: " && ret=0 825 ;; 826 (restart|stop) 827 _arguments $(__docker_arguments) \ 828 $opts_help \ 829 "($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)" \ 830 "($help -)*:containers:__docker_runningcontainers" && ret=0 831 ;; 832 (rm) 833 _arguments $(__docker_arguments) \ 834 $opts_help \ 835 "($help -f --force)"{-f,--force}"[Force removal]" \ 836 "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ 837 "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ 838 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 839 ;; 840 (rmi) 841 _arguments $(__docker_arguments) \ 842 $opts_help \ 843 "($help -f --force)"{-f,--force}"[Force removal]" \ 844 "($help)--no-prune[Do not delete untagged parents]" \ 845 "($help -)*: :__docker_images" && ret=0 846 ;; 847 (run) 848 _arguments $(__docker_arguments) \ 849 $opts_help \ 850 $opts_cpumemlimit \ 851 $opts_create \ 852 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 853 "($help)--rm[Remove intermediate containers when it exits]" \ 854 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 855 "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ 856 "($help -): :__docker_images" \ 857 "($help -):command: _command_names -e" \ 858 "($help -)*::arguments: _normal" && ret=0 859 860 case $state in 861 (link) 862 if compset -P "*:"; then 863 _wanted alias expl "Alias" compadd -E "" && ret=0 864 else 865 __docker_runningcontainers -qS ":" && ret=0 866 fi 867 ;; 868 esac 869 870 ;; 871 (save) 872 _arguments $(__docker_arguments) \ 873 $opts_help \ 874 "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ 875 "($help -)*: :__docker_images" && ret=0 876 ;; 877 (search) 878 _arguments $(__docker_arguments) \ 879 $opts_help \ 880 "($help)--automated[Only show automated builds]" \ 881 "($help)--no-trunc[Do not truncate output]" \ 882 "($help -s --stars)"{-s=,--stars=}"[Only display with at least X stars]:stars:(0 10 100 1000)" \ 883 "($help -):term: " && ret=0 884 ;; 885 (start) 886 _arguments $(__docker_arguments) \ 887 $opts_help \ 888 "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ 889 "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ 890 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 891 ;; 892 (stats) 893 _arguments $(__docker_arguments) \ 894 $opts_help \ 895 "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ 896 "($help)--no-stream[Disable streaming stats and only pull the first result]" \ 897 "($help -)*:containers:__docker_runningcontainers" && ret=0 898 ;; 899 (tag) 900 _arguments $(__docker_arguments) \ 901 $opts_help \ 902 "($help -f --force)"{-f,--force}"[force]"\ 903 "($help -):source:__docker_images"\ 904 "($help -):destination:__docker_repositories_with_tags" && ret=0 905 ;; 906 (top) 907 _arguments $(__docker_arguments) \ 908 $opts_help \ 909 "($help -)1:containers:__docker_runningcontainers" \ 910 "($help -)*:: :->ps-arguments" && ret=0 911 case $state in 912 (ps-arguments) 913 _ps && ret=0 914 ;; 915 esac 916 917 ;; 918 (volume) 919 local curcontext="$curcontext" state 920 _arguments $(__docker_arguments) \ 921 $opts_help \ 922 "($help -): :->command" \ 923 "($help -)*:: :->option-or-argument" && ret=0 924 925 case $state in 926 (command) 927 __docker_volume_commands && ret=0 928 ;; 929 (option-or-argument) 930 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 931 __docker_volume_subcommand && ret=0 932 ;; 933 esac 934 ;; 935 (wait) 936 _arguments $(__docker_arguments) \ 937 $opts_help \ 938 "($help -)*:containers:__docker_runningcontainers" && ret=0 939 ;; 940 (help) 941 _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 942 ;; 943 esac 944 945 return ret 946 } 947 948 _docker() { 949 # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 950 # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 951 if [[ $service != docker ]]; then 952 _call_function - _$service 953 return 954 fi 955 956 local curcontext="$curcontext" state line help="-h --help" 957 integer ret=1 958 typeset -A opt_args 959 960 _arguments $(__docker_arguments) -C \ 961 "(: -)"{-h,--help}"[Print usage]" \ 962 "($help)--config[Location of client config files]:path:_directories" \ 963 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 964 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 965 "($help -l --log-level)"{-l=,--log-level=}"[Set the logging level]:level:(debug info warn error fatal)" \ 966 "($help)--tls[Use TLS]" \ 967 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 968 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 969 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 970 "($help)--tlsverify[Use TLS and verify the remote]" \ 971 "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ 972 "($help -v --version)"{-v,--version}"[Print version information and quit]" \ 973 "($help -): :->command" \ 974 "($help -)*:: :->option-or-argument" && ret=0 975 976 local host=${opt_args[-H]}${opt_args[--host]} 977 local config=${opt_args[--config]} 978 local docker_options="${host:+--host $host} ${config:+--config $config}" 979 980 case $state in 981 (command) 982 __docker_commands && ret=0 983 ;; 984 (option-or-argument) 985 curcontext=${curcontext%:*:*}:docker-$words[1]: 986 __docker_subcommand && ret=0 987 ;; 988 esac 989 990 return ret 991 } 992 993 _docker "$@" 994 995 # Local Variables: 996 # mode: Shell-Script 997 # sh-indentation: 4 998 # indent-tabs-mode: nil 999 # sh-basic-offset: 4 1000 # End: 1001 # vim: ft=zsh sw=4 ts=4 et