723af07a566cbadc26e61f69c44a1a67ed1ba0c8

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
Carlo Sala <carlosalag@protonmail.com>
Date

Message

fix(docker): add static completion script

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/docker/_docker b/plugins/docker/_docker
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..466b09d94cf03e85f9ffbe6b0b75d6bc4967c21f
  4--- /dev/null
  5+++ b/plugins/docker/_docker
  6@@ -0,0 +1,3126 @@
  7+#compdef docker dockerd
  8+#
  9+# zsh completion for docker (http://docker.com)
 10+#
 11+# version:  0.3.0
 12+# github:   https://github.com/felixr/docker-zsh-completion
 13+#
 14+# contributors:
 15+#   - Felix Riedel
 16+#   - Steve Durrheimer
 17+#   - Vincent Bernat
 18+#   - Rohan Verma
 19+#
 20+# license:
 21+#
 22+# Copyright (c) 2013, Felix Riedel
 23+# All rights reserved.
 24+#
 25+# Redistribution and use in source and binary forms, with or without
 26+# modification, are permitted provided that the following conditions are met:
 27+#     * Redistributions of source code must retain the above copyright
 28+#       notice, this list of conditions and the following disclaimer.
 29+#     * Redistributions in binary form must reproduce the above copyright
 30+#       notice, this list of conditions and the following disclaimer in the
 31+#       documentation and/or other materials provided with the distribution.
 32+#     * Neither the name of the <organization> nor the
 33+#       names of its contributors may be used to endorse or promote products
 34+#       derived from this software without specific prior written permission.
 35+#
 36+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 37+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 38+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 39+# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 40+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 41+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 42+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 44+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 45+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 46+#
 47+
 48+# Short-option stacking can be enabled with:
 49+#  zstyle ':completion:*:*:docker:*' option-stacking yes
 50+#  zstyle ':completion:*:*:docker-*:*' option-stacking yes
 51+__docker_arguments() {
 52+    if zstyle -t ":completion:${curcontext}:" option-stacking; then
 53+        print -- -s
 54+    fi
 55+}
 56+
 57+__docker_get_containers() {
 58+    [[ $PREFIX = -* ]] && return 1
 59+    integer ret=1
 60+    local kind type line s
 61+    declare -a running stopped lines args names
 62+
 63+    kind=$1; shift
 64+    type=$1; shift
 65+    [[ $kind = (stopped|all) ]] && args=($args -a)
 66+
 67+    lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}})
 68+
 69+    # Parse header line to find columns
 70+    local i=1 j=1 k header=${lines[1]}
 71+    declare -A begin end
 72+    while (( j < ${#header} - 1 )); do
 73+        i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
 74+        j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
 75+        k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
 76+        begin[${header[$i,$((j-1))]}]=$i
 77+        end[${header[$i,$((j-1))]}]=$k
 78+    done
 79+    end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line
 80+    lines=(${lines[2,-1]})
 81+
 82+    # Container ID
 83+    if [[ $type = (ids|all) ]]; then
 84+        for line in $lines; do
 85+            s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}"
 86+            s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
 87+            s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
 88+            if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then
 89+                stopped=($stopped $s)
 90+            else
 91+                running=($running $s)
 92+            fi
 93+        done
 94+    fi
 95+
 96+    # Names: we only display the one without slash. All other names
 97+    # are generated and may clutter the completion. However, with
 98+    # Swarm, all names may be prefixed by the swarm node name.
 99+    if [[ $type = (names|all) ]]; then
100+        for line in $lines; do
101+            names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}})
102+            # First step: find a common prefix and strip it (swarm node case)
103+            (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/}
104+            # Second step: only keep the first name without a /
105+            s=${${names:#*/*}[1]}