a207a38d634cc10441636bc4359cd8a18c502dea
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/docker-compose/README.md b/plugins/docker-compose/README.md
2index 77b98f30df1ff85b1bebf4ed213548408f26fddb..567b821487af846fa41948fea666f7de6280954f 100644
3--- a/plugins/docker-compose/README.md
4+++ b/plugins/docker-compose/README.md
5@@ -1 +1,5 @@
6 # Docker-compose plugin for oh my zsh
7+
8+A copy of the completion script from the [docker-compose](1) git repo.
9+
10+[1]:[https://github.com/docker/compose/blob/master/contrib/completion/zsh/_docker-compose]
11diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose
12new file mode 100644
13index 0000000000000000000000000000000000000000..19c06675ad5057dd09b3398e476744ac8fdd8b10
14--- /dev/null
15+++ b/plugins/docker-compose/_docker-compose
16@@ -0,0 +1,308 @@
17+#compdef docker-compose
18+
19+# Description
20+# -----------
21+# zsh completion for docker-compose
22+# https://github.com/sdurrheimer/docker-compose-zsh-completion
23+# -------------------------------------------------------------------------
24+# Version
25+# -------
26+# 0.1.0
27+# -------------------------------------------------------------------------
28+# Authors
29+# -------
30+# * Steve Durrheimer <s.durrheimer@gmail.com>
31+# -------------------------------------------------------------------------
32+# Inspiration
33+# -----------
34+# * @albers docker-compose bash completion script
35+# * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion
36+# -------------------------------------------------------------------------
37+
38+# For compatibility reasons, Compose and therefore its completion supports several
39+# stack compositon files as listed here, in descending priority.
40+# Support for these filenames might be dropped in some future version.
41+__docker-compose_compose_file() {
42+ local file
43+ for file in docker-compose.y{,a}ml fig.y{,a}ml ; do
44+ [ -e $file ] && {
45+ echo $file
46+ return
47+ }
48+ done
49+ echo docker-compose.yml
50+}
51+
52+# Extracts all service names from docker-compose.yml.
53+___docker-compose_all_services_in_compose_file() {
54+ local already_selected
55+ local -a services
56+ already_selected=$(echo ${words[@]} | tr " " "|")
57+ awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | grep -Ev "$already_selected"
58+}
59+
60+# All services, even those without an existing container
61+__docker-compose_services_all() {
62+ services=$(___docker-compose_all_services_in_compose_file)
63+ _alternative "args:services:($services)"
64+}
65+
66+# All services that have an entry with the given key in their docker-compose.yml section
67+___docker-compose_services_with_key() {
68+ local already_selected
69+ local -a buildable
70+ already_selected=$(echo ${words[@]} | tr " " "|")
71+ # flatten sections to one line, then filter lines containing the key and return section name.
72+ awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | awk -F: -v key=": +$1:" '$0 ~ key {print $1}' 2>/dev/null | grep -Ev "$already_selected"
73+}
74+
75+# All services that are defined by a Dockerfile reference
76+__docker-compose_services_from_build() {
77+ buildable=$(___docker-compose_services_with_key build)
78+ _alternative "args:buildable services:($buildable)"
79+}
80+
81+# All services that are defined by an image
82+__docker-compose_services_from_image() {
83+ pullable=$(___docker-compose_services_with_key image)
84+ _alternative "args:pullable services:($pullable)"
85+}
86+
87+__docker-compose_get_services() {
88+ local kind expl
89+ declare -a running stopped lines args services
90+
91+ docker_status=$(docker ps > /dev/null 2>&1)
92+ if [ $? -ne 0 ]; then
93+ _message "Error! Docker is not running."
94+ return 1
95+ fi
96+
97+ kind=$1
98+ shift
99+ [[ $kind = (stopped|all) ]] && args=($args -a)
100+
101+ lines=(${(f)"$(_call_program commands docker ps ${args})"})
102+ services=(${(f)"$(_call_program commands docker-compose 2>/dev/null ${compose_file:+-f $compose_file} ${compose_project:+-p $compose_project} ps -q)"})
103+
104+ # Parse header line to find columns
105+ local i=1 j=1 k header=${lines[1]}
106+ declare -A begin end
107+ while (( $j < ${#header} - 1 )) {
108+ i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1))
109+ j=$(( $i + ${${header[$i,-1]}[(i) ]} - 1))
110+ k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2))
111+ begin[${header[$i,$(($j-1))]}]=$i
112+ end[${header[$i,$(($j-1))]}]=$k
113+ }
114+ lines=(${lines[2,-1]})
115+
116diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh
117deleted file mode 100644
118index 08500408d7a309a116bd8064c829f8fbaea59722..0000000000000000000000000000000000000000
119--- a/plugins/docker-compose/docker-compose.plugin.zsh
120+++ /dev/null
121@@ -1,14 +0,0 @@
122-# Authors:
123-# https://github.com/tristola
124-#
125-# Docker-compose related zsh aliases
126-
127-# Aliases ###################################################################
128-
129-alias dcup='docker-compose up'
130-alias dcb='docker-compose build'
131-alias dcrm='docker-compose rm'
132-alias dcps='docker-compose ps'
133-alias dcstop='docker-compose stop'
134-alias dcrestart='docker-compose restart'
135-