Skip to content

Commit d79dc85

Browse files
committed
Merge pull request #887 from albers/multiple-configfiles
Bash completion supports fig.yml and other legacy filenames
2 parents 22aca1a + 27e4f98 commit d79dc85

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

contrib/completion/bash/docker-compose

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,34 @@
1717
# . ~/.docker-compose-completion.sh
1818

1919

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.
2135
___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
2337
}
2438

2539
# All services, even those without an existing container
2640
__docker-compose_services_all() {
2741
COMPREPLY=( $(compgen -W "$(___docker-compose_all_services_in_compose_file)" -- "$cur") )
2842
}
2943

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
3145
___docker-compose_services_with_key() {
3246
# 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}'
3448
}
3549

3650
# All services that are defined by a Dockerfile reference

0 commit comments

Comments
 (0)