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