Blame view

plugins/docker/_docker 14.5 KB
093a6c34b   mj   Squashed 'repos/r...
1
2
3
4
5
6
7
8
9
10
11
12
13
  #compdef docker
  
  # Docker autocompletion for oh-my-zsh
  # Requires: Docker installed
  # Author: Azaan (@aeonazaan)
  # Updates: Bob Maerten (@bobmaerten) for Docker v0.9+
  #          Paul van den Berg (@bergvandenp) for Docker v1.3+ 
  
  
  # ----- Helper functions
  # Output a selectable list of all running docker containers
  __docker_containers() {
      declare -a cont_cmd
56a5793ce   mj   Squashed 'repos/r...
14
      cont_cmd=($(docker ps | awk 'NR>1{print $NF":[CON("$1")"$2"("$3")]"}'))
3de415e65   mj   Squashed 'repos/r...
15
16
17
18
19
20
21
22
23
24
      if [[  'X$cont_cmd' != 'X' ]]
          _describe 'containers' cont_cmd
  }
  
  # Output a selectable list of all containers, even not running
  __docker_all_containers() {
      declare -a cont_cmd
      cont_cmd=($(docker ps -a | awk 'NR>1{print $NF":[CON("$1")"$2"("$3")]"}'))
      if [[  'X$cont_cmd' != 'X' ]]
          _describe 'containers' cont_cmd
093a6c34b   mj   Squashed 'repos/r...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  }
  
  # output a selectable list of all docker images
  __docker_images() {
      declare -a img_cmd
      img_cmd=($(docker images | awk 'NR>1{print $1}'))
      _describe 'images' img_cmd
  }
  
  # ----- Commands
  # Seperate function for each command, makes extension easier later
  # ---------------------------
  __attach() {
      _arguments \
238d8e65a   mj   Squashed 'repos/r...
39
          '--no-stdin[Do not attach STDIN]' \
093a6c34b   mj   Squashed 'repos/r...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
          '--sig-proxy[Proxify all received signal to the process (even in non-tty mode)]'
      __docker_containers
  }
  
  __build() {
      _arguments \
          '--no-cache[Do not use cache when building the image]' \
          '(-q,--quiet)'{-q,--quiet}'[Suppress the verbose output generated by the containers]' \
          '--rm[Remove intermediate containers after a successful build]' \
          '(-t,--tag=)'{-t,--tag=}'[Repository name (and optionally a tag) to be applied to the resulting image in case of success]' \
          '*:files:_files'
  }
  
  __commit() {
      _arguments \
238d8e65a   mj   Squashed 'repos/r...
55
56
          '(-a,--author=)'{-a,--author=}'[Author (e.g. "John Hannibal Smith <hannibal@a-team.com>")]' \
          '(-c,--change=)'{-c,--change=}'[Apply Dockerfile instruction to the created image]' \
093a6c34b   mj   Squashed 'repos/r...
57
          '(-m,--message=)'{-m,--message=}'[Commit message]' \
238d8e65a   mj   Squashed 'repos/r...
58
          '(-p,--pause=)'{-p,--pause=}'[Pause container during commit]' \
093a6c34b   mj   Squashed 'repos/r...
59
60
61
62
63
  }
  
  __cp() {
      __docker_containers
  }
238d8e65a   mj   Squashed 'repos/r...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  __create() {
      _arguments \
          '(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \
          '(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR]' \
          '--add-host=[Add a custom host-to-IP mapping]' \
          '--cap-add=[Add Linux capabilities]' \
          '--cap-drop=[Drop Linux capabilities]' \
          '--cpuset-cpus=[CPUs in which to allow execution (0-3, 0,1)]' \
          '(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \
          '--cidfile=[Write the container ID to the file]' \
          '--device=[Add a host device to the container]' \
          '--dns=[Set custom dns servers]' \
          '--dns-search=[Set custom DNS search domains]' \
          '(-e,--env=)'{-e,--env=}'[Set environment variables]' \
          '--env-file=[Read in a file of environment variables]' \
          '--entrypoint=[Overwrite the default entrypoint of the image]' \
          '--expose=[Expose a port from the container without publishing it to your host]' \
          '(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \
          '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
          '--ipc=[IPC namespace to use]' \
          '(-l,--label=)'{-l,--label=}'[Set meta data on a container]' \
          '--link=[Add link to another container (name:alias)]' \
          '--log-driver=[Logging driver for the container]' \
          '--lxc-conf=[Add custom LXC options]' \
          '--mac-address=[Container MAC address (e.g. 92:d0:c6:0a:29:33)]' \
          '(-m,--memory=)'{-m,--memory=}'[Memory limit (format: <number><optional unit>, where unit = b, k, m or g)]' \
          '--net=[Set the Network mode for the container]' \
          '--name=[Assign a name to the container]' \
          '--pid=[PID namespace to use]' \
          '(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host (format: ip:hostPort:containerPort/protocol)]' \
          '--privileged=[Give extended privileges to this container]' \
          '--restart=[Restart policy to apply when a container exits]' \
          '--security-opt=[Security Options]' \
          '--sig-proxy=[Proxify all received signal to the process (even in non-tty mode)]' \
          '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-tty]' \
          '(-u,--user=)'{-u,--user=}'[Username or UID]' \
          '--ulimit=[Ulimit options]' \
          '(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g. -v /host:/container or -v /container)]' \
          '--volumes-from=[Mount volumes from the specified container(s)]' \
          '(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]'
      __docker_images
  }
093a6c34b   mj   Squashed 'repos/r...
106
107
108
  __diff() {
      __docker_containers
  }
3de415e65   mj   Squashed 'repos/r...
109
  __events() {    
093a6c34b   mj   Squashed 'repos/r...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
      _arguments \
          '--since=[Show previously created events and then stream.]'
  }
  
  __export() {
     __docker_containers
  }
  
  __history() {
      _arguments \
          '--no-trunc=[Don''t truncate output]' \
          '(-q,--quiet)'{-q,--quiet}'[Only show numeric IDs]'
      __docker_images
  }
  
  __images() {
      _arguments \
          '(-a,--all)'{-a,--all}'[Show all images (by default filter out the intermediate images used to build)]' \
          '--no-trunc[Don''t truncate output]' \
          '(-q,--quiet=)'{-q,--quiet=}'[Only show numeric IDs]' \
          '(-t,--tree=)'{-t,--tree=}'[Output graph in tree format]' \
          '(-v,--viz=)'{-v,--viz=}'[Output graph in graphviz format]'
      __docker_images
  }
  
  __import() {
      _arguments '*:files:_files'
  }
  
  __info() {
      # no arguments
  }
093a6c34b   mj   Squashed 'repos/r...
142
143
  __inspect() {
      __docker_images
3de415e65   mj   Squashed 'repos/r...
144
      __docker_all_containers
093a6c34b   mj   Squashed 'repos/r...
145
146
147
  }
  
  __kill() {
3de415e65   mj   Squashed 'repos/r...
148
149
      _arguments \
          '(-s,--signal=)'{-s,--signal=}'[KILL Signal]'
093a6c34b   mj   Squashed 'repos/r...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
      __docker_containers
  }
  
  __load() {
      _arguments '*:files:_files'
  }
  
  __login() {
      _arguments \
          '(-e,--email=)'{-e,-email=}'[Email]' \
          '(-p,--password=)'{-p,-password=}'[Password]' \
          '(-u,--username=)'{-u,-username=}'[Username]'
  }
  
  __logs() {
      _arguments \
          '(-f,--follow)'{-f,-follow}'[Follow log output]'
      __docker_containers
  }
  
  __port() {
      __docker_containers
  }
  
  __top() {
      __docker_containers
  }
  
  __ps() {
      _arguments \
          '(-a,--all)'{-a,--all}'[Show all containers. Only running containers are shown by default.]' \
          '--before-id=[Show only container created before Id, include non-running ones.]' \
          '(-l,--latest)'{-l,--latest}'[Show only the latest created container, include non-running ones.]' \
          '-n=[Show n last created containers, include non-running ones. default=-1.]' \
          '--no-trunc[Don''t truncate output]' \
          '(-q,--quiet)'{-q,--quiet}'[Only display numeric IDs]' \
          '(-s,--size)'{-s,--size}'[Display sizes]' \
          '--since-id=[Show only containers created since Id, include non-running ones.]'
  }
  
  __pull() {
      _arguments \
          '(-t,--tag=)'{-t,--tag=}'[Download tagged image in repository]'
  }
  
  __push() {
      # no arguments
  }
  
  __restart() {
      _arguments \
          '(-t,--time=)'{-t,--time=}'[Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default=10]'
      __docker_containers
  }
  
  __rm() {
      _arguments \
          '(-f,--force=)'{-f,--force=}'[Force removal of running container]' \
          '(-l,--link=)'{-l,--link=}'[Remove the specified link and not the underlying container]' \
          '(-v,--volumes=)'{-v,--volumes=}'[Remove the volumes associated to the container]'
3de415e65   mj   Squashed 'repos/r...
210
      __docker_all_containers
093a6c34b   mj   Squashed 'repos/r...
211
212
213
214
215
216
217
218
219
220
221
  }
  
  __rmi() {
      _arguments \
          '(-f,--force=)'{-f,--force=}'[Force]'
      __docker_images
  }
  
  __run() {
      _arguments \
          '(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \
238d8e65a   mj   Squashed 'repos/r...
222
223
224
225
226
227
          '(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR]' \
          '--add-host=[Add a custom host-to-IP mapping]' \
          '--cap-add=[Add Linux capabilities]' \
          '--cap-drop=[Drop Linux capabilities]' \
          '--cpuset-cpus=[CPUs in which to allow execution (0-3, 0,1)]' \
          '(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \
093a6c34b   mj   Squashed 'repos/r...
228
          '--cidfile=[Write the container ID to the file]' \
238d8e65a   mj   Squashed 'repos/r...
229
230
          '(-d,--detach=)'{-d,--detach=}'[Run container in the background, print new container id]' \
          '--device=[Add a host device to the container]' \
093a6c34b   mj   Squashed 'repos/r...
231
          '--dns=[Set custom dns servers]' \
238d8e65a   mj   Squashed 'repos/r...
232
          '--dns-search=[Set custom DNS search domains]' \
093a6c34b   mj   Squashed 'repos/r...
233
          '(-e,--env=)'{-e,--env=}'[Set environment variables]' \
238d8e65a   mj   Squashed 'repos/r...
234
          '--env-file=[Read in a file of environment variables]' \
093a6c34b   mj   Squashed 'repos/r...
235
236
237
          '--entrypoint=[Overwrite the default entrypoint of the image]' \
          '--expose=[Expose a port from the container without publishing it to your host]' \
          '(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \
238d8e65a   mj   Squashed 'repos/r...
238
239
240
          '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
          '--ipc=[IPC namespace to use]' \
          '(-l,--label=)'{-l,--label=}'[Set meta data on a container]' \
093a6c34b   mj   Squashed 'repos/r...
241
          '--link=[Add link to another container (name:alias)]' \
238d8e65a   mj   Squashed 'repos/r...
242
243
244
          '--log-driver=[Logging driver for the container]' \
          '--lxc-conf=[Add custom LXC options]' \
          '--mac-address=[Container MAC address (e.g. 92:d0:c6:0a:29:33)]' \
093a6c34b   mj   Squashed 'repos/r...
245
          '(-m,--memory=)'{-m,--memory=}'[Memory limit (format: <number><optional unit>, where unit = b, k, m or g)]' \
238d8e65a   mj   Squashed 'repos/r...
246
          '--net=[Set the Network mode for the container]' \
093a6c34b   mj   Squashed 'repos/r...
247
          '--name=[Assign a name to the container]' \
238d8e65a   mj   Squashed 'repos/r...
248
249
          '--pid=[PID namespace to use]' \
          '(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host (format: ip:hostPort:containerPort/protocol)]' \
093a6c34b   mj   Squashed 'repos/r...
250
          '--privileged=[Give extended privileges to this container]' \
238d8e65a   mj   Squashed 'repos/r...
251
          '--restart=[Restart policy to apply when a container exits]' \
093a6c34b   mj   Squashed 'repos/r...
252
          '--rm=[Automatically remove the container when it exits (incompatible with -d)]' \
238d8e65a   mj   Squashed 'repos/r...
253
          '--security-opt=[Security Options]' \
093a6c34b   mj   Squashed 'repos/r...
254
255
256
          '--sig-proxy=[Proxify all received signal to the process (even in non-tty mode)]' \
          '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-tty]' \
          '(-u,--user=)'{-u,--user=}'[Username or UID]' \
238d8e65a   mj   Squashed 'repos/r...
257
258
          '--ulimit=[Ulimit options]' \
          '(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g. -v /host:/container or -v /container)]' \
093a6c34b   mj   Squashed 'repos/r...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
          '--volumes-from=[Mount volumes from the specified container(s)]' \
          '(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]'
      __docker_images
  }
  
  __search() {
      _arguments \
          '--no-trunc=[Don''t truncate output]' \
          '-s,--stars=)'{-s,--stars=}'[Only displays with at least xxx stars]' \
          '-t,--trusted=)'{-t,--trusted=}'[Only show trusted builds]'
  }
  
  __save() {
      __docker_images
  }
  
  __start() {
      _arguments \
238d8e65a   mj   Squashed 'repos/r...
277
278
          '(-a,--attach=)'{-a,--attach=}'[Attach container''s STDOUT/STDERR and forward all signals to the process]' \
          '(-i,--interactive=)'{-i,--interactive=}'[Attach container''s STDIN]'
3de415e65   mj   Squashed 'repos/r...
279
      __docker_all_containers
093a6c34b   mj   Squashed 'repos/r...
280
  }
56a5793ce   mj   Squashed 'repos/r...
281
282
283
  __stats() {
      __docker_containers
  }
093a6c34b   mj   Squashed 'repos/r...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  __stop() {
      _arguments \
          '(-t,--time=)'{-t,--time=}'[Number of seconds to wait for the container to stop before killing it.]'
      __docker_containers
  }
  
  __tag() {
      _arguments \
          '(-f,--force=)'{-f,--force=}'[Force]'
      __docker_images
  }
  
  __version() {
      # no arguments
  }
  
  __wait() {
      __docker_containers
  }
  
  __exec() {
      _arguments \
        '(-d,--detach=)'{-d,--detach=}'[Detached mode: run command in the background]' \
        '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
        '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-TTY]'
      __docker_containers
  }
  
  # end commands ---------
  # ----------------------
  
  local -a _1st_arguments
  _1st_arguments=(
      "attach":"Attach to a running container"
      "build":"Build a container from a Dockerfile"
      "commit":"Create a new image from a container's changes"
      "cp":"Copy files/folders from the containers filesystem to the host path"
238d8e65a   mj   Squashed 'repos/r...
321
      "create":"Create new container without running it"
093a6c34b   mj   Squashed 'repos/r...
322
323
324
325
326
327
328
      "diff":"Inspect changes on a container's filesystem"
      "events":"Get real time events from the server"
      "export":"Stream the contents of a container as a tar archive"
      "history":"Show the history of an image"
      "images":"List images"
      "import":"Create a new filesystem image from the contents of a tarball"
      "info":"Display system-wide information"
093a6c34b   mj   Squashed 'repos/r...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
      "inspect":"Return low-level information on a container"
      "kill":"Kill a running container"
      "load":"Load an image from a tar archive"
      "login":"Register or Login to the docker registry server"
      "logs":"Fetch the logs of a container"
      "port":"Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"
      "ps":"List containers"
      "pull":"Pull an image or a repository from the docker registry server"
      "push":"Push an image or a repository to the docker registry server"
      "restart":"Restart a running container"
      "rm":"Remove one or more containers"
      "rmi":"Remove one or more images"
      "run":"Run a command in a new container"
      "save":"Save an image to a tar archive"
      "search":"Search for an image in the docker index"
      "start":"Start a stopped container"
56a5793ce   mj   Squashed 'repos/r...
345
      "stats":"Display a live stream of one or more containers' resource usage statistics"
093a6c34b   mj   Squashed 'repos/r...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
      "stop":"Stop a running container"
      "tag":"Tag an image into a repository"
      "top":"Lookup the running processes of a container"
      "version":"Show the docker version information"
      "wait":"Block until a container stops, then print its exit code"
      "exec":"Run a task inside a running container"
  )
  
  _arguments '*:: :->command'
  
  if (( CURRENT == 1 )); then
      _describe -t commands "docker command" _1st_arguments
      return
  fi
  
  local -a _command_args
  case "$words[1]" in
      attach)
         __attach ;;
      build)
          __build ;;
      commit)
          __commit ;;
      cp)
          __cp ;;
238d8e65a   mj   Squashed 'repos/r...
371
372
      create)
          __create ;;
093a6c34b   mj   Squashed 'repos/r...
373
374
375
376
377
378
379
380
381
382
383
384
385
386
      diff)
          __diff ;;
      events)
          __events ;;
      export)
          __export ;;
      history)
          __history ;;
      images)
          __images ;;
      import)
          __import ;;
      info)
          __info ;;
093a6c34b   mj   Squashed 'repos/r...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
      inspect)
          __inspect ;;
      kill)
          __kill ;;
      load)
          __load ;;
      login)
          __login ;;
      logs)
          __logs ;;
      port)
          __port ;;
      ps)
          __ps ;;
      pull)
          __pull ;;
      push)
          __push ;;
      restart)
          __restart ;;
      rm)
          __rm ;;
      rmi)
          __rmi ;;
      run)
          __run ;;
      save)
          __save ;;
      search)
          __search ;;
56a5793ce   mj   Squashed 'repos/r...
417
418
      stats)
          __stats ;;
093a6c34b   mj   Squashed 'repos/r...
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
      start)
          __start ;;
      stop)
          __stop ;;
      tag)
          __tag ;;
      top)
          __top ;;
      version)
          __version ;;
      wait)
          __wait ;;
      exec)
          __exec ;;
  esac