|
17 | 17 | # . ~/.docker-compose-completion.sh |
18 | 18 |
|
19 | 19 |
|
20 | | -# Extracts all service names from docker-compose.yml. |
| 20 | +# For compatibility reasons, Compose and therefore its completion supports several |
| 21 | +# stack compositon files as listed here, in descending priority. |
| 22 | +# Support for these filenames might be dropped in some future version. |
| 23 | +__docker-compose_compose_file() { |
| 24 | + local file |
| 25 | + for file in docker-compose.y{,a}ml fig.y{,a}ml ; do |
| 26 | + [ -e $file ] && { |
| 27 | + echo $file |
| 28 | + return |
| 29 | + } |
| 30 | + done |
| 31 | + echo docker-compose.yml |
| 32 | +} |
| 33 | + |
| 34 | +# Extracts all service names from the compose file. |
21 | 35 | ___docker-compose_all_services_in_compose_file() { |
22 | | - awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-docker-compose.yml}" |
| 36 | + awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null |
23 | 37 | } |
24 | 38 |
|
25 | 39 | # All services, even those without an existing container |
26 | 40 | __docker-compose_services_all() { |
27 | 41 | COMPREPLY=( $(compgen -W "$(___docker-compose_all_services_in_compose_file)" -- "$cur") ) |
28 | 42 | } |
29 | 43 |
|
30 | | -# All services that have an entry with the given key in their docker-compose.yml section |
| 44 | +# All services that have an entry with the given key in their compose_file section |
31 | 45 | ___docker-compose_services_with_key() { |
32 | 46 | # flatten sections to one line, then filter lines containing the key and return section name. |
33 | | - awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-docker-compose.yml}" | awk -F: -v key=": +$1:" '$0 ~ key {print $1}' |
| 47 | + awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-$(__docker-compose_compose_file)}" | awk -F: -v key=": +$1:" '$0 ~ key {print $1}' |
34 | 48 | } |
35 | 49 |
|
36 | 50 | # All services that are defined by a Dockerfile reference |
|
0 commit comments