Skip to content

Commit b79ddbd

Browse files
committed
feat: auto-generate and install shell completions via Homebrew
- Add completions.sh script to generate shell completions during build - Include completion files in release archives - Configure homebrew_casks to install completions automatically - Completions installed to standard Homebrew locations - Users get completions automatically, no manual setup needed
1 parent c2de6fa commit b79ddbd

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,4 @@ extract_data.js
191191
# Temporary test files
192192
test_output/
193193
tmp/
194+
completions/

.goreleaser.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ before:
44
hooks:
55
- go mod tidy
66
- go test ./...
7+
- ./scripts/completions.sh
78

89
builds:
910
- id: tokenizer
@@ -65,6 +66,7 @@ archives:
6566
files:
6667
- LICENSE
6768
- README.md
69+
- completions/*
6870

6971
checksum:
7072
name_template: 'checksums.txt'
@@ -200,20 +202,11 @@ homebrew_casks:
200202
system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/tokenizer"], sudo: false
201203
end
202204
203-
# Shell completions
205+
# Shell completions (files included in the archive)
204206
completions:
205-
bash:
206-
completion: |
207-
output = Utils.safe_popen_read("#{staged_path}/tokenizer", "completion", "bash")
208-
(bash_completion/"tokenizer").write output
209-
zsh:
210-
completion: |
211-
output = Utils.safe_popen_read("#{staged_path}/tokenizer", "completion", "zsh")
212-
(zsh_completion/"_tokenizer").write output
213-
fish:
214-
completion: |
215-
output = Utils.safe_popen_read("#{staged_path}/tokenizer", "completion", "fish")
216-
(fish_completion/"tokenizer.fish").write output
207+
bash: completions/tokenizer.bash
208+
zsh: completions/tokenizer.zsh
209+
fish: completions/tokenizer.fish
217210

218211
# Custom caveats
219212
caveats: |

scripts/completions.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Generating shell completions..."
5+
6+
# Build the binary first if it doesn't exist
7+
if [ ! -f ./tokenizer ]; then
8+
echo "Building tokenizer binary..."
9+
go build -o tokenizer ./cmd/tokenizer
10+
fi
11+
12+
# Create completions directory
13+
mkdir -p completions
14+
15+
# Generate completions for each shell
16+
echo "Generating bash completion..."
17+
./tokenizer completion bash > completions/tokenizer.bash
18+
19+
echo "Generating zsh completion..."
20+
./tokenizer completion zsh > completions/tokenizer.zsh
21+
22+
echo "Generating fish completion..."
23+
./tokenizer completion fish > completions/tokenizer.fish
24+
25+
echo "Completions generated successfully!"
26+
27+
# Clean up temporary binary
28+
rm -f ./tokenizer

0 commit comments

Comments
 (0)