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