Skip to content

Commit d6fa33a

Browse files
committed
Built completions with Completely
1 parent c411097 commit d6fa33a

File tree

9 files changed

+315
-110
lines changed

9 files changed

+315
-110
lines changed

.github/workflows/pr.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@ jobs:
6262
- name: Validate nginx conf
6363
run: |
6464
docker compose --file templates/${{ matrix.version }}/${{ matrix.compose_file}} run --rm nginx nginx -t
65+
66+
check-bash-completion:
67+
runs-on: ubuntu-latest
68+
69+
name: Check that Bash completion is up to date
70+
steps:
71+
- uses: actions/checkout@v5
72+
- uses: go-task/setup-task@v1
73+
74+
- name: Build completion
75+
run: task completion:build
76+
77+
- name: Check that nothing has changed
78+
run: git diff --exit-code

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,28 @@ The certificate is located in `./treafik/ssl/docker.crt` in this repository.
127127

128128
### Bash
129129

130-
You can install completions for `bash` by running:
130+
You can install completions for `bash` by adding
131131

132132
```sh
133-
ln -s $(git rev-parse --show-toplevel)/completion/bash/itkdev-docker-compose-completion.bash $(brew --prefix)/etc/bash_completion.d/itkdev-docker-compose
133+
eval "$(itkdev-docker-compose completions)"
134134
```
135135

136+
to your `~/.bashrc`.
137+
136138
### Zsh
137139

138-
You can install completions for `zsh` by updating `fpath` in `~/.zshrc`, e.g. by running:
140+
Add
139141

140142
```sh
141-
echo "fpath=($(git rev-parse --show-toplevel)/completion/zsh \$fpath) # itkdev-docker " >> ~/.zshrc
143+
# Load completion functions
144+
autoload -Uz +X compinit && compinit
145+
autoload -Uz +X bashcompinit && bashcompinit
146+
147+
eval "$(itkdev-docker-compose completions)"
142148
```
143149

150+
to your `~/.zshrc`. If you are using Oh-My-Zsh, you can leave out the `autoload` incantations.
151+
144152
### Docker UI
145153

146154
If you want a graphical user interface to see what images and containers are

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version: "3"
44

55
includes:
66
github-actions: ./task/Taskfile.github-actions.yml
7+
completion:
8+
taskfile: ./completion/Taskfile.yml
9+
dir: ./completion
710

811
vars:
912
GITHUB_ACTIONS_TEMPLATES_HEADER: |

completion/Taskfile.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
2+
3+
version: "3"
4+
5+
env:
6+
COMPLETELY_CONFIG_PATH: itkdev-docker-compose.completely.yaml
7+
COMPLETELY_OUTPUT_PATH: itkdev-docker-compose-completion.bash
8+
9+
tasks:
10+
build:
11+
desc: Build completion script for Bash
12+
cmds:
13+
- task: completely
14+
vars:
15+
TASK_ARGS: generate
16+
17+
test:
18+
desc: Template completions
19+
cmds:
20+
# Notice: The completions are not sorted alphabetically when running `completely test`.
21+
- for:
22+
- "itkdev-docker-compose -"
23+
- "itkdev-docker-compose u"
24+
- "itkdev-docker-compose op"
25+
- "itkdev-docker-compose dru"
26+
- "itkdev-docker-compose s"
27+
- "itkdev-docker-compose sy"
28+
- "itkdev-docker-compose sync:"
29+
- "itkdev-docker-compose templa"
30+
- "itkdev-docker-compose template:install -"
31+
task: completely
32+
vars:
33+
TASK_ARGS: test '{{.ITEM}}'
34+
silent: true
35+
36+
completely:
37+
desc: Run completely (https://github.com/bashly-framework/completely). Example `{{.TASK}} preview`
38+
cmds:
39+
- docker run --rm --env COMPLETELY_CONFIG_PATH --env COMPLETELY_OUTPUT_PATH --env COMPLETELY_DEBUG --user $(id -u):$(id -g) --volume "$PWD:/app" dannyben/completely {{.TASK_ARGS}} {{.CLI_ARGS}}

completion/bash/itkdev-docker-compose-completion.bash

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# itkdev-docker-compose completion -*- shell-script -*-
2+
3+
# This bash completions script was generated by
4+
# completely (https://github.com/bashly-framework/completely)
5+
# Modifying it manually is not recommended
6+
7+
_itkdev-docker-compose_completions_filter() {
8+
local words="$1"
9+
local cur=${COMP_WORDS[COMP_CWORD]}
10+
local result=()
11+
12+
# words the user already typed (excluding the command itself)
13+
local used=()
14+
if ((COMP_CWORD > 1)); then
15+
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
16+
fi
17+
18+
if [[ "${cur:0:1}" == "-" ]]; then
19+
# Completing an option: offer everything (including options)
20+
echo "$words"
21+
22+
else
23+
# Completing a non-option: offer only non-options,
24+
# and don't re-offer ones already used earlier in the line.
25+
for word in $words; do
26+
[[ "${word:0:1}" == "-" ]] && continue
27+
28+
local seen=0
29+
for u in "${used[@]}"; do
30+
if [[ "$u" == "$word" ]]; then
31+
seen=1
32+
break
33+
fi
34+
done
35+
((!seen)) && result+=("$word")
36+
done
37+
38+
echo "${result[*]}"
39+
fi
40+
}
41+
42+
_itkdev-docker-compose_completions() {
43+
local cur=${COMP_WORDS[COMP_CWORD]}
44+
local compwords=()
45+
if ((COMP_CWORD > 0)); then
46+
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
47+
fi
48+
local compline="${compwords[*]}"
49+
50+
COMPREPLY=()
51+
52+
case "$compline" in
53+
'template:install'*)
54+
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_itkdev-docker-compose_completions_filter "--force --list")" -- "$cur")
55+
;;
56+
57+
'template:update'*)
58+
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_itkdev-docker-compose_completions_filter "--force")" -- "$cur")
59+
;;
60+
61+
*)
62+
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_itkdev-docker-compose_completions_filter "--help url open drush self:update sync sync:db sync:files sql:cli sql:connect sql:log sql:open sql:port template:install template:update traefik:start traefik:stop traefik:url traefik:open traefik:logs traefik:pull mail:url mail:open mailhog:url mailhog:open xdebug xdebug3 hosts:insert images:pull shell composer php down version")" -- "$cur")
63+
;;
64+
65+
esac
66+
} &&
67+
complete -F _itkdev-docker-compose_completions itkdev-docker-compose
68+
69+
# ex: filetype=sh
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# https://github.com/bashly-framework/completely?tab=readme-ov-file#configuration-syntax
2+
3+
itkdev-docker-compose:
4+
- --help
5+
6+
# url [service [port]]
7+
# Print url to site or a service
8+
#
9+
# Protip: run
10+
#
11+
# brew install jq
12+
#
13+
# for improved handling of Traefik host names using jq (https://stedolan.github.io/jq/).
14+
- url
15+
16+
# open [service [port]]
17+
# Open url in default browser
18+
- open
19+
20+
# drush
21+
# Run drush command. If drush in installed via composer,
22+
# the vendor/bin/drush command is run inside the phpfpm
23+
# container. Otherwise, the drush container is used to
24+
# run the command.
25+
- drush
26+
27+
# self:update
28+
# Update this script and other stuff.
29+
- self:update
30+
31+
# sync
32+
# Sync both database and files.
33+
- sync
34+
35+
# sync:db
36+
# Sync database base on 'REMOTE_DB_DUMP_CMD' in the env
37+
# file.
38+
#
39+
# If 'SYNC_DB_POST_SCRIPT' is set, it will be eval'ed after
40+
# importing the remote database.
41+
- sync:db
42+
43+
# sync:files
44+
# Sync files base on 'REMOTE_PATH' or 'LOCAL_PATH' in
45+
# the env file.
46+
- sync:files
47+
48+
# sql:cli
49+
# Open MySQL client to the database (named `db`) in the database
50+
# container (`mariadb`).
51+
#
52+
# Execute a SQL query from the command line:
53+
#
54+
# itkdev-docker-compose sql:cli --table <<< 'SHOW TABLES'
55+
#
56+
# Run a SQL script:
57+
#
58+
# itkdev-docker-compose sql:cli < query.sql
59+
- sql:cli
60+
61+
# sql:connect
62+
# Print mysql command for connecting to database (named
63+
# `db`) in the database container (`mariadb`).
64+
#
65+
# Use `$(itkdev-docker-compose sql:connect)` to open the
66+
# database cli.
67+
- sql:connect
68+
69+
# sql:log
70+
# Log SQL queries sent to database.
71+
- sql:log
72+
73+
# sql:open
74+
# Open database GUI and connect to MariaDB.
75+
- sql:open
76+
77+
# sql:port
78+
# Display the exposed MariaDB SQL server port.
79+
- sql:port
80+
81+
# template:install name [--force] [--list]
82+
# Install a named docker-composer template in the current
83+
# directory.
84+
- template:install:
85+
- --force
86+
- --list
87+
88+
# template:update [--force]
89+
# Update template installed in project.
90+
- template:update:
91+
- --force
92+
93+
# traefik:start
94+
# Start traefik reverse proxy.
95+
- traefik:start
96+
97+
# traefik:stop
98+
# Stop traefik reverse proxy
99+
- traefik:stop
100+
101+
# traefik:url
102+
# URL for the administrative UI for traefik.
103+
- traefik:url
104+
105+
# traefik:open
106+
# Open the administrative UI for traefik.
107+
- traefik:open
108+
109+
# traefik:logs
110+
# See traefik logs
111+
- traefik:logs
112+
113+
# traefik:pull
114+
# Pull latest traefik & socket-proxy containers
115+
- traefik:pull
116+
117+
# mail:url
118+
# URL for the test mail web interface.
119+
- mail:url
120+
121+
# mail:open
122+
# Open test mail web interface in default browser.
123+
- mail:open
124+
125+
# mailhog:url
126+
# URL for the mailhog web-interface.
127+
- mailhog:url
128+
129+
# mailhog:open
130+
# Open mailhog url in default browser
131+
- mailhog:open
132+
133+
# xdebug
134+
# Boot the containers with PHP xdebug support enabled.
135+
- xdebug
136+
137+
# xdebug3
138+
# Boot the containers with PHP xdebug support enabled.
139+
# Consider using `xdebug` for an improved developer experience.
140+
- xdebug3
141+
142+
# hosts:insert
143+
# Insert the docker site url into the hosts file.
144+
- hosts:insert
145+
146+
# images:pull
147+
# Update/pull all docker images.
148+
- images:pull
149+
150+
# shell [service name]
151+
# Enter into /usr/bin/env sh inside container. E.g. itkdev-docker-compose shell phpfpm
152+
- shell
153+
154+
# composer
155+
# Run composer command inside phpfpm container
156+
- composer
157+
158+
# php
159+
# Run php command inside phpfpm container
160+
- php
161+
162+
# bin/*
163+
# vendor/bin/*
164+
# Run command command inside phpfpm container
165+
166+
# down
167+
# Stop and remove containers, networks, images, and volumes
168+
- down
169+
170+
# version
171+
# Display this tool's current version
172+
- version

0 commit comments

Comments
 (0)