github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/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 # - Vincent Bernat 11 # 12 # license: 13 # 14 # Copyright (c) 2013, Felix Riedel 15 # All rights reserved. 16 # 17 # Redistribution and use in source and binary forms, with or without 18 # modification, are permitted provided that the following conditions are met: 19 # * Redistributions of source code must retain the above copyright 20 # notice, this list of conditions and the following disclaimer. 21 # * Redistributions in binary form must reproduce the above copyright 22 # notice, this list of conditions and the following disclaimer in the 23 # documentation and/or other materials provided with the distribution. 24 # * Neither the name of the <organization> nor the 25 # names of its contributors may be used to endorse or promote products 26 # derived from this software without specific prior written permission. 27 # 28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 32 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 33 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 35 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 # 39 40 __docker_get_containers() { 41 local kind expl 42 declare -a running stopped lines args 43 44 kind=$1 45 shift 46 [[ $kind = (stopped|all) ]] && args=($args -a) 47 48 lines=(${(f)"$(_call_program commands docker ps ${args})"}) 49 50 # Parse header line to find columns 51 local i=1 j=1 k header=${lines[1]} 52 declare -A begin end 53 while (( $j < ${#header} - 1 )) { 54 i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1)) 55 j=$(( $i + ${${header[$i,-1]}[(i) ]} - 1)) 56 k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2)) 57 begin[${header[$i,$(($j-1))]}]=$i 58 end[${header[$i,$(($j-1))]}]=$k 59 } 60 lines=(${lines[2,-1]}) 61 62 # Container ID 63 local line 64 local s 65 for line in $lines; do 66 s="${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" 67 s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 68 s="$s, ${${${line[$begin[IMAGE],$end[IMAGE]]}/:/\\:}%% ##}" 69 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 70 stopped=($stopped $s) 71 else 72 running=($running $s) 73 fi 74 done 75 76 # Names 77 local name 78 local -a names 79 for line in $lines; do 80 names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}}) 81 for name in $names; do 82 s="${name}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 83 s="$s, ${${${line[$begin[IMAGE],$end[IMAGE]]}/:/\\:}%% ##}" 84 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 85 stopped=($stopped $s) 86 else 87 running=($running $s) 88 fi 89 done 90 done 91 92 [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running 93 [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped 94 } 95 96 __docker_stoppedcontainers() { 97 __docker_get_containers stopped "$@" 98 } 99 100 __docker_runningcontainers() { 101 __docker_get_containers running "$@" 102 } 103 104 __docker_containers () { 105 __docker_get_containers all "$@" 106 } 107 108 __docker_images () { 109 local expl 110 declare -a images 111 images=(${${${${(f)"$(_call_program commands docker images)"}[2,-1]}/ ##/\\:}%% *}) 112 images=(${${images%\\:<none>}#<none>} ${${${(f)"$(_call_program commands docker images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) 113 _describe -t docker-images "images" images 114 } 115 116 __docker_tags() { 117 local expl 118 declare -a tags 119 tags=(${${${${${(f)"$(_call_program commands docker images)"}#* }## #}%% *}[2,-1]}) 120 _describe -t docker-tags "tags" tags 121 } 122 123 __docker_repositories_with_tags() { 124 if compset -P '*:'; then 125 __docker_tags 126 else 127 __docker_repositories -qS ":" 128 fi 129 } 130 131 __docker_search() { 132 # declare -a dockersearch 133 local cache_policy 134 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 135 if [[ -z "$cache_policy" ]]; then 136 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 137 fi 138 139 local searchterm cachename 140 searchterm="${words[$CURRENT]%/}" 141 cachename=_docker-search-$searchterm 142 143 local expl 144 local -a result 145 if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ 146 && ! _retrieve_cache ${cachename#_}; then 147 _message "Searching for ${searchterm}..." 148 result=(${${${(f)"$(_call_program commands docker search $searchterm)"}%% *}[2,-1]}) 149 _store_cache ${cachename#_} result 150 fi 151 _wanted dockersearch expl 'available images' compadd -a result 152 } 153 154 __docker_caching_policy() 155 { 156 oldp=( "$1"(Nmh+1) ) # 1 hour 157 (( $#oldp )) 158 } 159 160 161 __docker_repositories () { 162 local expl 163 declare -a repos 164 repos=(${${${(f)"$(_call_program commands docker images)"}%% *}[2,-1]}) 165 _describe -t docker-repos "repositories" repos "$@" 166 } 167 168 __docker_commands () { 169 # local -a _docker_subcommands 170 local cache_policy 171 172 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 173 if [[ -z "$cache_policy" ]]; then 174 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 175 fi 176 177 if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ 178 && ! _retrieve_cache docker_subcommands; 179 then 180 local -a lines 181 lines=(${(f)"$(_call_program commands docker 2>&1)"}) 182 _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) 183 _docker_subcommands=($_docker_subcommands 'help:Show help for a command') 184 _store_cache docker_subcommands _docker_subcommands 185 fi 186 _describe -t docker-commands "docker command" _docker_subcommands 187 } 188 189 __docker_subcommand () { 190 local -a _command_args 191 case "$words[1]" in 192 (attach) 193 _arguments \ 194 '(- :)--help[Print usage]' \ 195 '--no-stdin[Do not attach stdin]' \ 196 '--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]' \ 197 ':containers:__docker_runningcontainers' && ret=0 198 ;; 199 (build) 200 _arguments \ 201 '(-c --cpu-share)'{-c,--cpu-share=-}'[CPU shares (relative weight)]:CPU shares: ' \ 202 '--cgroup-parent=-[Optional parent cgroup for the container]:cgroup parent: ' \ 203 '--cpu-period=-[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: ' \ 204 '--cpu-quota=-[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: ' \ 205 '--cpuset-cpus=-[CPUs in which to allow execution (0-3, 0,1)]:CPUs: ' \ 206 '--cpuset-mems=-[MEMs in which to allow execution (0-3, 0,1)]:MEMs: ' \ 207 '(-f --file)'{-f,--file=-}"[Name of the Dockerfile (Default is 'PATH/Dockerfile')]:Dockerfile:_files" \ 208 '--force-rm[Always remove intermediate containers]' \ 209 '(- :)--help[Print usage]' \ 210 '(-m --memory)'{-m,--memory=-}'[Memory limit]:Memory limit: ' \ 211 '--memory-swap=-[Total memory (memory + swap), '-1' to disable swap]' \ 212 '--no-cache[Do not use cache when building the image]' \ 213 '--pull[Always attempt to pull a newer version of the image]' \ 214 '(-q --quiet)'{-q,--quiet}'[Suppress the verbose output generated by the containers]' \ 215 '--rm[Remove intermediate containers after a successful build]' \ 216 '(-t --tag)'{-t,--tag=-}'[Repository name (and optionally a tag) for the image]:repository:__docker_repositories_with_tags' \ 217 ':path or URL:_directories' && ret=0 218 ;; 219 (commit) 220 _arguments \ 221 '(-a --author)'{-a,--author=-}'[Author]:author: ' \ 222 '*'{-c,--change=-}'[Apply Dockerfile instruction to the created image]' \ 223 '(- :)--help[Print usage]' \ 224 '(-m --message)'{-m,--message=-}'[Commit message]:message: ' \ 225 '(-p --pause)'{-p,--pause}'[Pause container during commit]' \ 226 ':container:__docker_containers' \ 227 ':repository:__docker_repositories_with_tags' && ret=0 228 ;; 229 (cp) 230 _arguments \ 231 '(- :)--help[Print usage]' \ 232 ':container:->container' \ 233 ':hostpath:_files' && ret=0 234 case $state in 235 (container) 236 if compset -P '*:'; then 237 _files 238 else 239 __docker_containers -qS ":" 240 fi 241 ;; 242 esac 243 ;; 244 (create) 245 _arguments \ 246 '*'{-a,--attach=-}'[Attach to STDIN, STDOUT or STDERR]:STD:(STDIN STDOUT STDERR)' \ 247 '*--add-host=-[Add a custom host-to-IP mapping (host:ip)]:host\:ip mapping: ' \ 248 '--blkio-weight=-[Block IO (relative weight), between 10 and 1000]:Block IO weight: ' \ 249 '(-c --cpu-shares)'{-c,--cpu-shares=-}'[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)' \ 250 '*--cap-add=-[Add Linux capabilities]:capability: ' \ 251 '*--cap-drop=-[Drop Linux capabilities]:capability: ' \ 252 '--cgroup-parent=-[Optional parent cgroup for the container]:cgroup parent: ' \ 253 '--cidfile=-[Write the container ID to the file]:CID:_files' \ 254 '--cpu-period=-[Limit CPU CFS (Completely Fair Scheduler) period]:CPU period: ' \ 255 '--cpu-quota=-[Limit the CPU CFS quota]:CPU quota: ' \ 256 '--cpuset-cpus=-[CPUs in which to allow execution (0-3, 0,1)]:CPUs: ' \ 257 '--cpuset-mems=-[MEMs in which to allow execution (0-3, 0,1)]:MEMs: ' \ 258 '*--device=-[Add a host device to the container]:device:_files' \ 259 '*--dns=-[Set custom dns servers]:dns server: ' \ 260 '*--dns-search=-[Set custom DNS search domains]:dns domains: ' \ 261 '*'{-e,--env=-}'[Set environment variables]:environment variable: ' \ 262 '--entrypoint=-[Overwrite the default ENTRYPOINT of the image]:entry point: ' \ 263 '*--env-file=-[Read in a file of environment variables]:environment file:_files' \ 264 '*--expose=-[Expose a port or a range of ports]:port or a range of ports: ' \ 265 '(-h --hostname)'{-h,--hostname=-}'[Container host name]:hostname:_hosts' \ 266 '(- :)--help[Print usage]' \ 267 '(-i --interactive)'{-i,--interactive}'[Keep STDIN open even if not attached]' \ 268 '--ipc=-[IPC namespace to use]:IPC namespace: ' \ 269 '*'{-l,--label=-}'[Set meta data on a container]:Label: ' \ 270 '*--label-file=-[Read in a line delimited file of labels]' \ 271 '*--link=-[Add link to another container]:link:->link' \ 272 '--log-driver=-[Logging driver for container]:Logging driver: ' \ 273 '*--log-opt=-[Log driver options]:Log driver options: ' \ 274 '*--lxc-conf=-[Add custom lxc options]:lxc options: ' \ 275 '(-m --memory)'{-m,--memory=-}'[Memory limit (in bytes)]:Memory limit: ' \ 276 '--mac-address=-[Container MAC address (e.g. 92:d0:c6:0a:29:33)]:MAC address: ' \ 277 "--memory-swap=-[Total memory (memory + swap), '-1' to disable swap]:Total memory: " \ 278 '--name=-[Assign a name to the container]:name: ' \ 279 '--net=-[Set the Network mode for the container]:network mode:(bridge none container host)' \ 280 '--oom-kill-disable[Disable OOM Killer]' \ 281 '(-P --publish-all)'{-P,--publish-all}'[Publish all exposed ports to random ports]' \ 282 '*'{-p,--publish=-}"[Publish a container's port(s) to the host]:port:_ports" \ 283 '--pid=-[PID namespace to use]:PID: ' \ 284 '--privileged[Give extended privileges to this container]' \ 285 "--read-only[Mount the container's root filesystem as read only]" \ 286 '--restart=-[Restart policy]:restart policy:(no on-failure always)' \ 287 '--rm[Remove intermediate containers when it exits]' \ 288 '*--security-opt=-[Security options]:security option: ' \ 289 '(-t --tty)'{-t,--tty}'[Allocate a pseudo-TTY]' \ 290 '(-u --user)'{-u,--user=-}'[Username or UID]:user:_users' \ 291 '*--ulimit=-[Ulimit options]:ulimit: ' \ 292 '--uts=-[UTS namespace to use]:UTS: ' \ 293 '*'{-v,--volume=-}'[Bind mount a volume]:volume: ' \ 294 '*--volumes-from=-[Mount volumes from the specified container]:volume: ' \ 295 '(-w --workdir)'{-w,--workdir=-}'[Working directory inside the container]:directory:_directories' \ 296 '(-):images:__docker_images' \ 297 '(-):command: _command_names -e' \ 298 '*::arguments: _normal' && ret=0 299 300 case $state in 301 (link) 302 if compset -P '*:'; then 303 _wanted alias expl 'Alias' compadd -E "" 304 else 305 __docker_runningcontainers -qS ":" 306 fi 307 ;; 308 esac 309 310 ;; 311 (diff) 312 _arguments \ 313 '(- :)--help[Print usage]' \ 314 '*:containers:__docker_containers' && ret=0 315 ;; 316 (events) 317 _arguments \ 318 '*'{-f,--filter=-}'[Filter output based on conditions provided]:filter: ' \ 319 '(- :)--help[Print usage]' \ 320 '--since=-[Show all events created since timestamp]:timestamp: ' \ 321 '--until=-[Stream events until this timestamp]:timestamp: ' && ret=0 322 ;; 323 (exec) 324 local state 325 _arguments \ 326 '(-d --detach)'{-d,--detach}'[Detached mode: run command in the background]' \ 327 '(- :)--help[Print usage]' \ 328 '(-i --interactive)'{-i,--interactive}'[Keep STDIN open even if not attached]' \ 329 '(-t --tty)'{-t,--tty}'[Allocate a pseudo-TTY]' \ 330 '(-u --user)'{-u,--user=-}'[Username or UID]:User: ' \ 331 ':containers:__docker_runningcontainers' \ 332 '*::command:->anycommand' && ret=0 333 334 case $state in 335 (anycommand) 336 shift 1 words 337 (( CURRENT-- )) 338 _normal 339 ;; 340 esac 341 342 return ret 343 ;; 344 (export) 345 _arguments \ 346 '(- :)--help[Print usage]' \ 347 '(-o --output)'{-o,--output=-}'[Write to a file, instead of STDOUT]:file: ' \ 348 '*:containers:__docker_containers' && ret=0 349 ;; 350 (history) 351 _arguments \ 352 '(-H --human)'{-H,--human}'[Print sizes and dates in human readable format]' \ 353 '(- :)--help[Print usage]' \ 354 '--no-trunc[Do not truncate output]' \ 355 '(-q --quiet)'{-q,--quiet}'[Only show numeric IDs]' \ 356 '*:images:__docker_images' && ret=0 357 ;; 358 (images) 359 _arguments \ 360 '(-a --all)'{-a,--all}'[Show all images (default hides intermediate images)]' \ 361 '--digests[Show digests]' \ 362 '*'{-f,--filter=-}'[Filter output based on conditions provided]:filter: ' \ 363 '(- :)--help[Print usage]' \ 364 '--no-trunc[Do not truncate output]' \ 365 '(-q --quiet)'{-q,--quiet}'[Only show numeric IDs]' \ 366 ':repository:__docker_repositories' && ret=0 367 ;; 368 (import) 369 _arguments \ 370 '*'{-c,--change=-}'[Apply Dockerfile instruction to the created image]' \ 371 '(- :)--help[Print usage]' \ 372 ':URL:(http:// file://)' \ 373 ':repository:__docker_repositories_with_tags' && ret=0 374 ;; 375 (info|version) 376 _arguments \ 377 '(- :)--help[Print usage]' && ret=0 378 ;; 379 (inspect) 380 _arguments \ 381 '(-f --format)'{-f,--format=-}'[Format the output using the given go template]:template: ' \ 382 '(- :)--help[Print usage]' \ 383 '*:containers:__docker_containers' && ret=0 384 ;; 385 (kill) 386 _arguments \ 387 '(- :)--help[Print usage]' \ 388 '(-s --signal)'{-s,--signal=-}'[Signal to send to the container]:signal:_signals' \ 389 '*:containers:__docker_runningcontainers' && ret=0 390 ;; 391 (load) 392 _arguments \ 393 '(- :)--help[Print usage]' \ 394 '(-i --input)'{-i,--input=-}'[Read from a tar archive file, instead of STDIN]:archive file:_files -g "*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)"' && ret=0 395 ;; 396 (login) 397 _arguments \ 398 '(-e --email)'{-e,--email=-}'[Email]:email: ' \ 399 '(- :)--help[Print usage]' \ 400 '(-p --password)'{-p,--password=-}'[Password]:password: ' \ 401 '(-u --user)'{-u,--user=-}'[Username]:username: ' \ 402 '1:server:->string' && ret=0 403 ;; 404 (logout) 405 _arguments \ 406 '(- :)--help[Print usage]' \ 407 '1:server:->string' && ret=0 408 ;; 409 (logs) 410 _arguments \ 411 '(-f --follow)'{-f,--follow}'[Follow log output]' \ 412 '(- :)--help[Print usage]' \ 413 '--since=-[Show logs since timestamp]:timestamp: ' \ 414 '(-t --timestamps)'{-t,--timestamps}'[Show timestamps]' \ 415 '--tail=-[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)' \ 416 '*:containers:__docker_containers' && ret=0 417 ;; 418 (pause|unpause) 419 _arguments \ 420 '(- :)--help[Print usage]' \ 421 '1:containers:__docker_runningcontainers' && ret=0 422 ;; 423 (port) 424 _arguments \ 425 '(- :)--help[Print usage]' \ 426 '1:containers:__docker_runningcontainers' \ 427 '2:port:_ports' && ret=0 428 ;; 429 (ps) 430 _arguments \ 431 '(-a --all)'{-a,--all}'[how all containers (default shows just running)]' \ 432 '--before=-[Show only container created before Id or Name]:containers:__docker_containers' \ 433 '*'{-f,--filter=-}'[Filter output based on conditions provided]:filter: ' \ 434 '(- :)--help[Print usage]' \ 435 '(-l --latest)'{-l,--latest}'[Show the latest created container, include non-running]' \ 436 '-n[Show n last created containers, include non-running]:n:(1 5 10 25 50)' \ 437 '--no-trunc[Do not truncate output]' \ 438 '(-q --quiet)'{-q,--quiet}'[Only show numeric IDs]' \ 439 '(-s --size)'{-s,--size}'[Display total file sizes]' \ 440 '--since=-[Show created since Id or Name, include non-running]:containers:__docker_containers' && ret=0 441 ;; 442 (pull) 443 _arguments \ 444 '(-a --all-tags)'{-a,--all-tags}'[Download all tagged images in the repository]' \ 445 '(- :)--help[Print usage]' \ 446 ':name:__docker_search' && ret=0 447 ;; 448 (push) 449 _arguments \ 450 '(- :)--help[Print usage]' \ 451 ':images:__docker_images' && ret=0 452 ;; 453 (rename) 454 _arguments \ 455 '(- :)--help[Print usage]' \ 456 ':old name:__docker_containers' \ 457 ':new name: ' && ret=0 458 ;; 459 (restart|stop) 460 _arguments \ 461 '(- :)--help[Print usage]' \ 462 '(-t --time)'{-t,--time=-}'[Seconds to wait for stop before killing the container]:seconds to before killing:(1 5 10 30 60)' \ 463 '*:containers:__docker_runningcontainers' && ret=0 464 ;; 465 (rm) 466 _arguments \ 467 '(-f --force)'{-f,--force}'[Force the removal of a running container (uses SIGKILL)]' \ 468 '(- :)--help[Print usage]' \ 469 '(-l --link)'{-l,--link}'[Remove the specified link and not the underlying container]' \ 470 '(-v --volumes)'{-v,--volumes}'[Remove the volumes associated to the container]' \ 471 '*:containers:__docker_stoppedcontainers' && ret=0 472 ;; 473 (rmi) 474 _arguments \ 475 '(-f --force)'{-f,--force}'[Force removal of the image]' \ 476 '(- :)--help[Print usage]' \ 477 '--no-prune[Do not delete untagged parents]' \ 478 '*:images:__docker_images' && ret=0 479 ;; 480 (run) 481 _arguments \ 482 '*'{-a,--attach=-}'[Attach to STDIN, STDOUT or STDERR]:STD:(STDIN STDOUT STDERR)' \ 483 '*--add-host=-[Add a custom host-to-IP mapping (host\:ip)]:host\:ip mapping: ' \ 484 '--blkio-weight=-[Block IO (relative weight), between 10 and 1000]:Block IO weight: ' \ 485 '(-c --cpu-shares)'{-c,--cpu-shares=-}'[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)' \ 486 '*--cap-add=-[Add Linux capabilities]:capability: ' \ 487 '*--cap-drop=-[Drop Linux capabilities]:capability: ' \ 488 '--cgroup-parent=-[Optional parent cgroup for the container]:cgroup parent: ' \ 489 '--cidfile=-[Write the container ID to the file]:CID file:_files' \ 490 '--cpu-period=-[Limit CPU CFS (Completely Fair Scheduler) period]:CPU period: ' \ 491 '--cpu-quota=-[Limit the CPU CFS quota]:CPU quota: ' \ 492 '--cpuset-cpus=-[CPUs in which to allow execution (0-3, 0,1)]:CPUs: ' \ 493 '--cpuset-mems=-[MEMs in which to allow execution (0-3, 0,1)]:MEMs: ' \ 494 '(-d --detach)'{-d,--detach}'[Run container in background and print container ID]' \ 495 '*--device=-[Add a host device to the container]:device:_files' \ 496 '*--dns=-[Set custom dns servers]:dns server: ' \ 497 '*--dns-search=-[Set custom DNS search domains]:dns domains: ' \ 498 '*'{-e,--env=-}'[Set environment variables]:environment variable: ' \ 499 '--entrypoint=-[Overwrite the default ENTRYPOINT of the image]:entry point: ' \ 500 '*--env-file=-[Read in a file of environment variables]:environment file:_files' \ 501 '*--expose=-[Expose a port or a range of ports]:port or a range of ports: ' \ 502 '(-h --hostname)'{-h,--hostname=-}'[Container host name]:hostname:_hosts' \ 503 '(- :)--help[Print usage]' \ 504 '(-i --interactive)'{-i,--interactive}'[Keep STDIN open even if not attached]' \ 505 '--ipc=-[IPC namespace to use]:IPC: ' \ 506 '*'{-l,--label=-}'[Set meta data on a container]:Label: ' \ 507 '*--label-file=-[Read in a line delimited file of labels]' \ 508 '*--link=-[Add link to another container]:link:->link' \ 509 '--log-driver=-[Logging driver for container]:Logging driver: ' \ 510 '*--log-opt=-[Log driver options]:Log driver options: ' \ 511 '*--lxc-conf=-[Add custom lxc options]:lxc options: ' \ 512 '(-m --memory)'{-m,--memory=-}'[Memory limit (in bytes)]:Memory limit: ' \ 513 '--mac-address=-[Container MAC address (e.g. 92:d0:c6:0a:29:33)]:MAC address: ' \ 514 "--memory-swap=-[Total memory (memory + swap), '-1' to disable swap]:Total memory: " \ 515 '--name=-[Assign a name to the container]:name: ' \ 516 '--net=-[Set the Network mode for the container]:network mode:(bridge none container host)' \ 517 '--oom-kill-disable[Disable OOM Killer]' \ 518 '(-P --publish-all)'{-P,--publish-all}'[Publish all exposed ports to random ports]' \ 519 '*'{-p,--publish=-}"[Publish a container's port(s) to the host]:port:_ports" \ 520 '--pid=-[PID namespace to use]:PID: ' \ 521 '--privileged[Give extended privileges to this container]' \ 522 "--read-only[Mount the container's root filesystem as read only]" \ 523 '--restart=-[Restart policy]:restart policy:(no on-failure always)' \ 524 '--rm[Remove intermediate containers when it exits]' \ 525 '*--security-opt=-[Security options]:security option: ' \ 526 '--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]' \ 527 '(-t --tty)'{-t,--tty}'[Allocate a pseudo-TTY]' \ 528 '(-u --user)'{-u,--user=-}'[Username or UID]:user:_users' \ 529 '*--ulimit=-[Ulimit options]:ulimit: ' \ 530 '--uts=-[UTS namespace to use]:UTS: ' \ 531 '*'{-v,--volume=-}'[Bind mount a volume]:volume: ' \ 532 '*--volumes-from=-[Mount volumes from the specified container]:volume: ' \ 533 '(-w --workdir)'{-w,--workdir=-}'[Working directory inside the container]:directory:_directories' \ 534 '(-):images:__docker_images' \ 535 '(-):command: _command_names -e' \ 536 '*::arguments: _normal' && ret=0 537 538 case $state in 539 (link) 540 if compset -P '*:'; then 541 _wanted alias expl 'Alias' compadd -E "" 542 else 543 __docker_runningcontainers -qS ":" 544 fi 545 ;; 546 esac 547 548 ;; 549 (save) 550 _arguments \ 551 '(- :)--help[Print usage]' \ 552 '(-o --output)'{-o,--output=-}'[Write to file]:file: ' \ 553 '*:images:__docker_images' && ret=0 554 ;; 555 (search) 556 _arguments \ 557 '--automated[Only show automated builds]' \ 558 '(- :)--help[Print usage]' \ 559 '--no-trunc[Do not truncate output]' \ 560 '(-s --stars)'{-s,--stars=-}'[Only display with at least X stars]:stars:(0 10 100 1000)' \ 561 '1:term:->string' && ret=0 562 ;; 563 (start) 564 _arguments \ 565 '(-a --attach)'{-a,--attach}'[Attach STDOUT/STDERR and forward signals]' \ 566 '(- :)--help[Print usage]' \ 567 '(-i --interactive)'{-i,--interactive}"[Attach container's STDIN]" \ 568 '*:containers:__docker_stoppedcontainers' && ret=0 569 ;; 570 (stats) 571 _arguments \ 572 '(- :)--help[Print usage]' \ 573 '--no-stream[Disable streaming stats and only pull the first result]' \ 574 '*:containers:__docker_runningcontainers' && ret=0 575 ;; 576 (tag) 577 _arguments \ 578 '(-f --force)'{-f,--force}'[force]'\ 579 '(- :)--help[Print usage]' \ 580 ':image:__docker_images'\ 581 ':repository:__docker_repositories_with_tags' && ret=0 582 ;; 583 (top) 584 _arguments \ 585 '(- :)--help[Print usage]' \ 586 '1:containers:__docker_runningcontainers' \ 587 '(-)*:: :->ps-arguments' && ret=0 588 case $state in 589 (ps-arguments) 590 _ps 591 ;; 592 esac 593 594 ;; 595 (wait) 596 _arguments \ 597 '(- :)--help[Print usage]' \ 598 '*:containers:__docker_runningcontainers' && ret=0 599 ;; 600 (help) 601 _arguments ':subcommand:__docker_commands' && ret=0 602 ;; 603 (*) 604 _message 'Unknown sub command' 605 esac 606 607 } 608 609 _docker () { 610 # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 611 # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 612 if [[ $service != docker ]]; then 613 _call_function - _$service 614 return 615 fi 616 617 local curcontext="$curcontext" state line ret=1 618 typeset -A opt_args 619 620 _arguments -C \ 621 '--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: ' \ 622 '(-b --bridge)'{-b,--bridge=-}'[Attach containers to a network bridge]:bridge: ' \ 623 '--bip=-[Specify network bridge IP]' \ 624 '(-D --debug)'{-D,--debug}'[Enable debug mode]' \ 625 '(-d --daeamon)'{-d,--daemon}'[Enable daemon mode]' \ 626 '--default-gateway[Container default gateway IPv4 address]:IPv4 address: ' \ 627 '--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: ' \ 628 '*--dns=-[DNS server to use]:DNS: ' \ 629 '*--dns-search=-[DNS search domains to use]' \ 630 '*--default-ulimit=-[Set default ulimit settings for containers]:ulimit: ' \ 631 '(-e --exec-driver)'{-e,--exec-driver=-}'[Exec driver to use]:driver:(native lxc Windows)' \ 632 '*--exec-opt=-[Set exec driver options]:exec driver options: ' \ 633 '--exec-root=-[Root of the Docker execdriver (default: /var/run/docker)]:PATH:_directories' \ 634 '--fixed-cidr=-[IPv4 subnet for fixed IPs]:IPv4 subnet: ' \ 635 '--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: ' \ 636 '(-G --group)'{-G,--group=-}'[Group for the unix socket (default: docker)]:group:_groups' \ 637 '(-g --graph)'{-g,--graph=-}'[Root of the Docker runtime (default: /var/lib/docker)]:PATH:_directories' \ 638 '(-H --host)'{-H,--host=-}'[tcp://host:port to bind/connect to]:socket: ' \ 639 '(-h --help)'{-h,--help}'[Print usage]' \ 640 '--icc[Enable inter-container communication]' \ 641 '*--insecure-registry=-[Enable insecure registry communication]:registry: ' \ 642 '--ip=-[Default IP when binding container ports (default: 0.0.0.0)]' \ 643 '--ip-forward=-[Enable net.ipv4.ip_forward]:enable:(true false)' \ 644 '--ip-masq=-[Enable IP masquerading]:enable:(true false)' \ 645 '--iptables=-[Enable addition of iptables rules]:enable:(true false)' \ 646 '--ipv6[Enable IPv6 networking]' \ 647 '(-l --log-level)'{-l,--log-level=-}'[Set the logging level]:level:(debug info warn error fatal)' \ 648 '*--label=-[Set key=value labels to the daemon]:label: ' \ 649 '--log-driver=-[Default driver for container logs (default: json-file)]:driver:(json-file syslog journald gelf none)' \ 650 '*--log-opt=-[Log driver specific options]:log driver options: ' \ 651 '--mtu=-[Set the containers network MTU (default: 0)]' \ 652 '(-p --pidfile)'{-p,--pidfile=-}'[Path to use for daemon PID file (default: /var/run/docker.pid)]:PID file PATH: ' \ 653 '*--registry-mirror=-[Preferred Docker registry mirror]:registry mirror: ' \ 654 '(-s --storage-driver)'{-s,--storage-driver=-}'[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)' \ 655 '--selinux-enabled[Enable selinux support]' \ 656 '*--storage-opt=-[Set storage driver options]:storage driver options: ' \ 657 '--tls[Use TLS; implied by --tlsverify]' \ 658 '--tlscacert=-[Trust certs signed only by this CA (default: ~/.docker/ca.pem)]' \ 659 '--tlscert=-[Path to TLS certificate file (default: ~/.docker/cert.pem)]' \ 660 '--tlskey=-[Path to TLS key file (default: ~/.docker/key.pem)]' \ 661 '--tlsverify[Use TLS and verify the remote]' \ 662 '--userland-proxy=-[Use userland proxy for loopback traffic]:enable:(true false)' \ 663 '(-v --version)'{-v,--version}'[Print version information and quit]' \ 664 '(-): :->command' \ 665 '(-)*:: :->option-or-argument' && ret=0 666 667 if (( CURRENT == 1 )); then 668 669 fi 670 case $state in 671 (command) 672 __docker_commands && ret=0 673 ;; 674 (option-or-argument) 675 curcontext=${curcontext%:*:*}:docker-$words[1]: 676 __docker_subcommand && ret=0 677 ;; 678 esac 679 680 return ret 681 } 682 683 _docker "$@" 684 685 # Local Variables: 686 # mode: Shell-Script 687 # sh-indentation: 4 688 # indent-tabs-mode: nil 689 # sh-basic-offset: 4 690 # End: 691 # vim: ft=zsh sw=4 ts=4 et