github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/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_containers" && 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)--internal[Restricts external access to the network]" \ 307 "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ 308 "($help)*--gateway=[ipv4 or ipv6 Gateway for the master subnet]:IP: " \ 309 "($help)*--aux-address[Auxiliary ipv4 or ipv6 addresses used by network driver]:key=IP: " \ 310 "($help)*"{-o=,--opt=}"[Set driver specific options]:key=value: " \ 311 "($help -)1:Network Name: " && ret=0 312 ;; 313 (inspect) 314 _arguments $(__docker_arguments) \ 315 $opts_help \ 316 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 317 "($help -)*:network:__docker_networks" && ret=0 318 ;; 319 (ls) 320 _arguments $(__docker_arguments) \ 321 $opts_help \ 322 "($help)--no-trunc[Do not truncate the output]" \ 323 "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 324 ;; 325 (rm) 326 _arguments $(__docker_arguments) \ 327 $opts_help \ 328 "($help -)*:network:__docker_networks" && ret=0 329 ;; 330 (help) 331 _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 332 ;; 333 esac 334 335 return ret 336 } 337 338 __docker_volumes() { 339 [[ $PREFIX = -* ]] && return 1 340 integer ret=1 341 declare -a lines volumes 342 343 lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"}) 344 345 # Parse header line to find columns 346 local i=1 j=1 k header=${lines[1]} 347 declare -A begin end 348 while (( j < ${#header} - 1 )); do 349 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 350 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 351 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 352 begin[${header[$i,$((j-1))]}]=$i 353 end[${header[$i,$((j-1))]}]=$k 354 done 355 end[${header[$i,$((j-1))]}]=-1 356 lines=(${lines[2,-1]}) 357 358 # Names 359 local line s 360 for line in $lines; do 361 s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" 362 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 363 volumes=($volumes $s) 364 done 365 366 _describe -t volumes-list "volumes" volumes && ret=0 367 return ret 368 } 369 370 __docker_volume_commands() { 371 local -a _docker_volume_subcommands 372 _docker_volume_subcommands=( 373 "create:Create a volume" 374 "inspect:Return low-level information on a volume" 375 "ls:List volumes" 376 "rm:Remove a volume" 377 ) 378 _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands 379 } 380 381 __docker_volume_subcommand() { 382 local -a _command_args opts_help 383 local expl help="--help" 384 integer ret=1 385 386 opts_help=("(: -)--help[Print usage]") 387 388 case "$words[1]" in 389 (create) 390 _arguments $(__docker_arguments) \ 391 $opts_help \ 392 "($help -d --driver)"{-d=,--driver=}"[Specify volume driver name]:Driver name:(local)" \ 393 "($help)--name=[Specify volume name]" \ 394 "($help)*"{-o=,--opt=}"[Set driver specific options]:Driver option: " && ret=0 395 ;; 396 (inspect) 397 _arguments $(__docker_arguments) \ 398 $opts_help \ 399 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 400 "($help -)1:volume:__docker_volumes" && ret=0 401 ;; 402 (ls) 403 _arguments $(__docker_arguments) \ 404 $opts_help \ 405 "($help)*"{-f=,--filter=}"[Provide filter values (i.e. 'dangling=true')]:filter: " \ 406 "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 407 ;; 408 (rm) 409 _arguments $(__docker_arguments) \ 410 $opts_help \ 411 "($help -):volume:__docker_volumes" && ret=0 412 ;; 413 (help) 414 _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 415 ;; 416 esac 417 418 return ret 419 } 420 421 __docker_caching_policy() { 422 oldp=( "$1"(Nmh+1) ) # 1 hour 423 (( $#oldp )) 424 } 425 426 __docker_commands() { 427 local cache_policy 428 429 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 430 if [[ -z "$cache_policy" ]]; then 431 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 432 fi 433 434 if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ 435 && ! _retrieve_cache docker_subcommands; 436 then 437 local -a lines 438 lines=(${(f)"$(_call_program commands docker 2>&1)"}) 439 _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) 440 _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') 441 (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands 442 fi 443 _describe -t docker-commands "docker command" _docker_subcommands 444 } 445 446 __docker_subcommand() { 447 local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update 448 local expl help="--help" 449 integer ret=1 450 451 opts_help=("(: -)--help[Print usage]") 452 opts_build_create_run=( 453 "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " 454 "($help)--isolation=[]:isolation:(default hyperv process)" 455 "($help)*--shm-size=[Size of '/dev/shm'. The format is '<number><unit>'. Default is '64m'.]:shm size: " 456 "($help)*--ulimit=[ulimit options]:ulimit: " 457 ) 458 opts_build_create_run_update=( 459 "($help)--cpu-shares=[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" 460 "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " 461 "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " 462 "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " 463 "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " 464 "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " 465 "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " 466 ) 467 opts_create_run=( 468 "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" 469 "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " 470 "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " 471 "($help)*--cap-add=[Add Linux capabilities]:capability: " 472 "($help)*--cap-drop=[Drop Linux capabilities]:capability: " 473 "($help)--cidfile=[Write the container ID to the file]:CID file:_files" 474 "($help)*--device=[Add a host device to the container]:device:_files" 475 "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " 476 "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " 477 "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " 478 "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " 479 "($help)*--dns=[Set custom DNS servers]:DNS server: " 480 "($help)*--dns-opt=[Set custom DNS options]:DNS option: " 481 "($help)*--dns-search=[Set custom DNS search domains]:DNS domains: " 482 "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " 483 "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " 484 "($help)*--env-file=[Read environment variables from a file]:environment file:_files" 485 "($help)*--expose=[Expose a port from the container without publishing it]: " 486 "($help)*--group-add=[Add additional groups to run as]:group:_groups" 487 "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" 488 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" 489 "($help)--ipc=[IPC namespace to use]:IPC namespace: " 490 "($help)*--link=[Add link to another container]:link:->link" 491 "($help)*"{-l=,--label=}"[Set meta data on a container]:label: " 492 "($help)--log-driver=[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs splunk none)" 493 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" 494 "($help)--mac-address=[Container MAC address]:MAC address: " 495 "($help)--name=[Container name]:name: " 496 "($help)--net=[Connect a container to a network]:network mode:(bridge none container host)" 497 "($help)--oom-kill-disable[Disable OOM Killer]" 498 "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" 499 "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" 500 "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" 501 "($help)--pid=[PID namespace to use]:PID: " 502 "($help)--privileged[Give extended privileges to this container]" 503 "($help)--read-only[Mount the container's root filesystem as read only]" 504 "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" 505 "($help)*--security-opt=[Security options]:security option: " 506 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" 507 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" 508 "($help)--tmpfs[mount tmpfs]" 509 "($help)*-v[Bind mount a volume]:volume: " 510 "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" 511 "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " 512 "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" 513 ) 514 opts_create_run_update=( 515 "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" 516 "($help)--kernel-memory=[Kernel memory limit in bytes.]:Memory limit: " 517 "($help)--memory-reservation=[Memory soft limit]:Memory limit: " 518 ) 519 520 case "$words[1]" in 521 (attach) 522 _arguments $(__docker_arguments) \ 523 $opts_help \ 524 "($help)--no-stdin[Do not attach stdin]" \ 525 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 526 "($help -):containers:__docker_runningcontainers" && ret=0 527 ;; 528 (build) 529 _arguments $(__docker_arguments) \ 530 $opts_help \ 531 $opts_build_create_run \ 532 $opts_build_create_run_update \ 533 "($help)*--build-arg[Set build-time variables]:<varname>=<value>: " \ 534 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ 535 "($help)--force-rm[Always remove intermediate containers]" \ 536 "($help)--no-cache[Do not use cache when building the image]" \ 537 "($help)--pull[Attempt to pull a newer version of the image]" \ 538 "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ 539 "($help)--rm[Remove intermediate containers after a successful build]" \ 540 "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \ 541 "($help -):path or URL:_directories" && ret=0 542 ;; 543 (commit) 544 _arguments $(__docker_arguments) \ 545 $opts_help \ 546 "($help -a --author)"{-a=,--author=}"[Author]:author: " \ 547 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 548 "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ 549 "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ 550 "($help -):container:__docker_containers" \ 551 "($help -): :__docker_repositories_with_tags" && ret=0 552 ;; 553 (cp) 554 _arguments $(__docker_arguments) \ 555 $opts_help \ 556 "($help -)1:container:->container" \ 557 "($help -)2:hostpath:_files" && ret=0 558 case $state in 559 (container) 560 if compset -P "*:"; then 561 _files && ret=0 562 else 563 __docker_containers -qS ":" && ret=0 564 fi 565 ;; 566 esac 567 ;; 568 (create) 569 _arguments $(__docker_arguments) \ 570 $opts_help \ 571 $opts_build_create_run \ 572 $opts_build_create_run_update \ 573 $opts_create_run \ 574 $opts_create_run_update \ 575 "($help -): :__docker_images" \ 576 "($help -):command: _command_names -e" \ 577 "($help -)*::arguments: _normal" && ret=0 578 579 case $state in 580 (link) 581 if compset -P "*:"; then 582 _wanted alias expl "Alias" compadd -E "" && ret=0 583 else 584 __docker_runningcontainers -qS ":" && ret=0 585 fi 586 ;; 587 esac 588 589 ;; 590 (daemon) 591 _arguments $(__docker_arguments) \ 592 $opts_help \ 593 "($help)--api-cors-header=[Set CORS headers in the remote API]:CORS headers: " \ 594 "($help)*--authorization-plugin=[Set authorization plugins to load]" \ 595 "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ 596 "($help)--bip=[Specify network bridge IP]" \ 597 "($help)--cgroup-parent=[Set parent cgroup for all containers]:cgroup: " \ 598 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 599 "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ 600 "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ 601 "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ 602 "($help)--cluster-advertise=[Address of the daemon instance to advertise]:Instance to advertise (host\:port): " \ 603 "($help)*--cluster-store-opt=[Set cluster options]:Cluster options:->cluster-store-options" \ 604 "($help)*--dns=[DNS server to use]:DNS: " \ 605 "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ 606 "($help)*--dns-opt=[DNS options to use]:DNS option: " \ 607 "($help)*--default-ulimit=[Set default ulimit settings for containers]:ulimit: " \ 608 "($help)--disable-legacy-registry[Do not contact legacy registries]" \ 609 "($help)*--exec-opt=[Set exec driver options]:exec driver options: " \ 610 "($help)--exec-root=[Root of the Docker execdriver]:path:_directories" \ 611 "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ 612 "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ 613 "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ 614 "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ 615 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 616 "($help)--icc[Enable inter-container communication]" \ 617 "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ 618 "($help)--ip=[Default IP when binding container ports]" \ 619 "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ 620 "($help)--ip-masq[Enable IP masquerading]" \ 621 "($help)--iptables[Enable addition of iptables rules]" \ 622 "($help)--ipv6[Enable IPv6 networking]" \ 623 "($help -l --log-level)"{-l=,--log-level=}"[Set the logging level]:level:(debug info warn error fatal)" \ 624 "($help)*--label=[Set key=value labels to the daemon]:label: " \ 625 "($help)--log-driver=[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs splunk none)" \ 626 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \ 627 "($help)--mtu=[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \ 628 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ 629 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ 630 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \ 631 "($help)--selinux-enabled[Enable selinux support]" \ 632 "($help)*--storage-opt=[Set storage driver options]:storage driver options: " \ 633 "($help)--tls[Use TLS]" \ 634 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 635 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 636 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 637 "($help)--tlsverify[Use TLS and verify the remote]" \ 638 "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ 639 "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0 640 641 case $state in 642 (cluster-store) 643 if compset -P '*://'; then 644 _message 'host:port' && ret=0 645 else 646 store=('consul' 'etcd' 'zk') 647 _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 648 fi 649 ;; 650 (cluster-store-options) 651 if compset -P '*='; then 652 _files && ret=0 653 else 654 opts=('kv.cacertfile' 'kv.certfile' 'kv.keyfile') 655 _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 656 fi 657 ;; 658 (users-groups) 659 if compset -P '*:'; then 660 _groups && ret=0 661 else 662 _describe -t userns-default "default Docker user management" '(default)' && ret=0 663 _users && ret=0 664 fi 665 ;; 666 esac 667 ;; 668 (diff) 669 _arguments $(__docker_arguments) \ 670 $opts_help \ 671 "($help -)*:containers:__docker_containers" && ret=0 672 ;; 673 (events) 674 _arguments $(__docker_arguments) \ 675 $opts_help \ 676 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 677 "($help)--since=[Events created since this timestamp]:timestamp: " \ 678 "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0 679 ;; 680 (exec) 681 local state 682 _arguments $(__docker_arguments) \ 683 $opts_help \ 684 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 685 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ 686 "($help)--privileged[Give extended Linux capabilities to the command]" \ 687 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ 688 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ 689 "($help -):containers:__docker_runningcontainers" \ 690 "($help -)*::command:->anycommand" && ret=0 691 692 case $state in 693 (anycommand) 694 shift 1 words 695 (( CURRENT-- )) 696 _normal && ret=0 697 ;; 698 esac 699 ;; 700 (export) 701 _arguments $(__docker_arguments) \ 702 $opts_help \ 703 "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ 704 "($help -)*:containers:__docker_containers" && ret=0 705 ;; 706 (history) 707 _arguments $(__docker_arguments) \ 708 $opts_help \ 709 "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ 710 "($help)--no-trunc[Do not truncate output]" \ 711 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 712 "($help -)*: :__docker_images" && ret=0 713 ;; 714 (images) 715 _arguments $(__docker_arguments) \ 716 $opts_help \ 717 "($help -a --all)"{-a,--all}"[Show all images]" \ 718 "($help)--digests[Show digests]" \ 719 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 720 "($help)--format[Pretty-print containers using a Go template]:format: " \ 721 "($help)--no-trunc[Do not truncate output]" \ 722 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 723 "($help -): :__docker_repositories" && ret=0 724 ;; 725 (import) 726 _arguments $(__docker_arguments) \ 727 $opts_help \ 728 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 729 "($help -m --message)"{-m=,--message=}"[Set commit message for imported image]:message: " \ 730 "($help -):URL:(- http:// file://)" \ 731 "($help -): :__docker_repositories_with_tags" && ret=0 732 ;; 733 (info|version) 734 _arguments $(__docker_arguments) \ 735 $opts_help && ret=0 736 ;; 737 (inspect) 738 local state 739 _arguments $(__docker_arguments) \ 740 $opts_help \ 741 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 742 "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ 743 "($help)--type=[Return JSON for specified type]:type:(image container)" \ 744 "($help -)*: :->values" && ret=0 745 746 case $state in 747 (values) 748 if [[ ${words[(r)--type=container]} == --type=container ]]; then 749 __docker_containers && ret=0 750 elif [[ ${words[(r)--type=image]} == --type=image ]]; then 751 __docker_images && ret=0 752 else 753 __docker_images && __docker_containers && ret=0 754 fi 755 ;; 756 esac 757 ;; 758 (kill) 759 _arguments $(__docker_arguments) \ 760 $opts_help \ 761 "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ 762 "($help -)*:containers:__docker_runningcontainers" && ret=0 763 ;; 764 (load) 765 _arguments $(__docker_arguments) \ 766 $opts_help \ 767 "($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 768 ;; 769 (login) 770 _arguments $(__docker_arguments) \ 771 $opts_help \ 772 "($help -e --email)"{-e=,--email=}"[Email]:email: " \ 773 "($help -p --password)"{-p=,--password=}"[Password]:password: " \ 774 "($help -u --user)"{-u=,--user=}"[Username]:username: " \ 775 "($help -)1:server: " && ret=0 776 ;; 777 (logout) 778 _arguments $(__docker_arguments) \ 779 $opts_help \ 780 "($help -)1:server: " && ret=0 781 ;; 782 (logs) 783 _arguments $(__docker_arguments) \ 784 $opts_help \ 785 "($help -f --follow)"{-f,--follow}"[Follow log output]" \ 786 "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ 787 "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ 788 "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ 789 "($help -)*:containers:__docker_containers" && ret=0 790 ;; 791 (network) 792 local curcontext="$curcontext" state 793 _arguments $(__docker_arguments) \ 794 $opts_help \ 795 "($help -): :->command" \ 796 "($help -)*:: :->option-or-argument" && ret=0 797 798 case $state in 799 (command) 800 __docker_network_commands && ret=0 801 ;; 802 (option-or-argument) 803 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 804 __docker_network_subcommand && ret=0 805 ;; 806 esac 807 ;; 808 (pause|unpause) 809 _arguments $(__docker_arguments) \ 810 $opts_help \ 811 "($help -)*:containers:__docker_runningcontainers" && ret=0 812 ;; 813 (port) 814 _arguments $(__docker_arguments) \ 815 $opts_help \ 816 "($help -)1:containers:__docker_runningcontainers" \ 817 "($help -)2:port:_ports" && ret=0 818 ;; 819 (ps) 820 _arguments $(__docker_arguments) \ 821 $opts_help \ 822 "($help -a --all)"{-a,--all}"[Show all containers]" \ 823 "($help)--before=[Show only container created before...]:containers:__docker_containers" \ 824 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 825 "($help)--format[Pretty-print containers using a Go template]:format: " \ 826 "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ 827 "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \ 828 "($help)--no-trunc[Do not truncate output]" \ 829 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 830 "($help -s --size)"{-s,--size}"[Display total file sizes]" \ 831 "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0 832 ;; 833 (pull) 834 _arguments $(__docker_arguments) \ 835 $opts_help \ 836 "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ 837 "($help -):name:__docker_search" && ret=0 838 ;; 839 (push) 840 _arguments $(__docker_arguments) \ 841 $opts_help \ 842 "($help -): :__docker_images" && ret=0 843 ;; 844 (rename) 845 _arguments $(__docker_arguments) \ 846 $opts_help \ 847 "($help -):old name:__docker_containers" \ 848 "($help -):new name: " && ret=0 849 ;; 850 (restart|stop) 851 _arguments $(__docker_arguments) \ 852 $opts_help \ 853 "($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)" \ 854 "($help -)*:containers:__docker_runningcontainers" && ret=0 855 ;; 856 (rm) 857 _arguments $(__docker_arguments) \ 858 $opts_help \ 859 "($help -f --force)"{-f,--force}"[Force removal]" \ 860 "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ 861 "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ 862 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 863 ;; 864 (rmi) 865 _arguments $(__docker_arguments) \ 866 $opts_help \ 867 "($help -f --force)"{-f,--force}"[Force removal]" \ 868 "($help)--no-prune[Do not delete untagged parents]" \ 869 "($help -)*: :__docker_images" && ret=0 870 ;; 871 (run) 872 _arguments $(__docker_arguments) \ 873 $opts_help \ 874 $opts_build_create_run \ 875 $opts_build_create_run_update \ 876 $opts_create_run \ 877 $opts_create_run_update \ 878 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 879 "($help)--rm[Remove intermediate containers when it exits]" \ 880 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 881 "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ 882 "($help -): :__docker_images" \ 883 "($help -):command: _command_names -e" \ 884 "($help -)*::arguments: _normal" && ret=0 885 886 case $state in 887 (link) 888 if compset -P "*:"; then 889 _wanted alias expl "Alias" compadd -E "" && ret=0 890 else 891 __docker_runningcontainers -qS ":" && ret=0 892 fi 893 ;; 894 esac 895 896 ;; 897 (save) 898 _arguments $(__docker_arguments) \ 899 $opts_help \ 900 "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ 901 "($help -)*: :__docker_images" && ret=0 902 ;; 903 (search) 904 _arguments $(__docker_arguments) \ 905 $opts_help \ 906 "($help)--automated[Only show automated builds]" \ 907 "($help)--no-trunc[Do not truncate output]" \ 908 "($help -s --stars)"{-s=,--stars=}"[Only display with at least X stars]:stars:(0 10 100 1000)" \ 909 "($help -):term: " && ret=0 910 ;; 911 (start) 912 _arguments $(__docker_arguments) \ 913 $opts_help \ 914 "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ 915 "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ 916 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 917 ;; 918 (stats) 919 _arguments $(__docker_arguments) \ 920 $opts_help \ 921 "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ 922 "($help)--no-stream[Disable streaming stats and only pull the first result]" \ 923 "($help -)*:containers:__docker_runningcontainers" && ret=0 924 ;; 925 (tag) 926 _arguments $(__docker_arguments) \ 927 $opts_help \ 928 "($help -f --force)"{-f,--force}"[force]"\ 929 "($help -):source:__docker_images"\ 930 "($help -):destination:__docker_repositories_with_tags" && ret=0 931 ;; 932 (top) 933 _arguments $(__docker_arguments) \ 934 $opts_help \ 935 "($help -)1:containers:__docker_runningcontainers" \ 936 "($help -)*:: :->ps-arguments" && ret=0 937 case $state in 938 (ps-arguments) 939 _ps && ret=0 940 ;; 941 esac 942 943 ;; 944 (update) 945 _arguments $(__docker_arguments) \ 946 $opts_help \ 947 $opts_create_run_update \ 948 $opts_build_create_run_update \ 949 "($help -)*: :->values" && ret=0 950 951 case $state in 952 (values) 953 if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then 954 __docker_stoppedcontainers && ret=0 955 else 956 __docker_containers && ret=0 957 fi 958 ;; 959 esac 960 ;; 961 (volume) 962 local curcontext="$curcontext" state 963 _arguments $(__docker_arguments) \ 964 $opts_help \ 965 "($help -): :->command" \ 966 "($help -)*:: :->option-or-argument" && ret=0 967 968 case $state in 969 (command) 970 __docker_volume_commands && ret=0 971 ;; 972 (option-or-argument) 973 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 974 __docker_volume_subcommand && ret=0 975 ;; 976 esac 977 ;; 978 (wait) 979 _arguments $(__docker_arguments) \ 980 $opts_help \ 981 "($help -)*:containers:__docker_runningcontainers" && ret=0 982 ;; 983 (help) 984 _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 985 ;; 986 esac 987 988 return ret 989 } 990 991 _docker() { 992 # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 993 # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 994 if [[ $service != docker ]]; then 995 _call_function - _$service 996 return 997 fi 998 999 local curcontext="$curcontext" state line help="-h --help" 1000 integer ret=1 1001 typeset -A opt_args 1002 1003 _arguments $(__docker_arguments) -C \ 1004 "(: -)"{-h,--help}"[Print usage]" \ 1005 "($help)--config[Location of client config files]:path:_directories" \ 1006 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 1007 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 1008 "($help -l --log-level)"{-l=,--log-level=}"[Set the logging level]:level:(debug info warn error fatal)" \ 1009 "($help)--tls[Use TLS]" \ 1010 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 1011 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 1012 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 1013 "($help)--tlsverify[Use TLS and verify the remote]" \ 1014 "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ 1015 "($help -v --version)"{-v,--version}"[Print version information and quit]" \ 1016 "($help -): :->command" \ 1017 "($help -)*:: :->option-or-argument" && ret=0 1018 1019 local host=${opt_args[-H]}${opt_args[--host]} 1020 local config=${opt_args[--config]} 1021 local docker_options="${host:+--host $host} ${config:+--config $config}" 1022 1023 case $state in 1024 (command) 1025 __docker_commands && ret=0 1026 ;; 1027 (option-or-argument) 1028 curcontext=${curcontext%:*:*}:docker-$words[1]: 1029 __docker_subcommand && ret=0 1030 ;; 1031 esac 1032 1033 return ret 1034 } 1035 1036 _docker "$@" 1037 1038 # Local Variables: 1039 # mode: Shell-Script 1040 # sh-indentation: 4 1041 # indent-tabs-mode: nil 1042 # sh-basic-offset: 4 1043 # End: 1044 # vim: ft=zsh sw=4 ts=4 et