From ef7b33f8ae5fe795747a1a33cd7b79df53037ef7 Mon Sep 17 00:00:00 2001 From: Self-Perfection Date: Sat, 24 Oct 2026 02:30:48 +0000 Subject: [PATCH 1/2] build: ship shell completions in deb/rpm/apk packages and the Nix flake GoReleaser generates bash, zsh and fish completions with `witr completion` before the build and nfpm installs them into each distro's standard directories. zsh's directory differs per packager: Debian's zsh only searches vendor-completions, Fedora's and Alpine's search site-functions. The flake installs the same completions with installShellCompletion, skipped when cross-compiling since that needs to run the built binary. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + .goreleaser.yml | 30 ++++++++++++++++++++++++++++++ README.md | 2 +- flake.nix | 7 +++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 65632d4e..2f9f6761 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ result # Ignore build artifacts dist/ pkg-dist/ +completions/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 88217877..bef083da 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,6 +2,12 @@ version: 2 project_name: witr +before: + hooks: + # Shell completions for the packages below. GoReleaser runs hooks without a + # shell, so the loop and redirection need an explicit sh -c. + - sh -c 'mkdir -p completions && for sh in bash zsh fish; do go run ./cmd/witr completion "$sh" > "completions/witr.$sh"; done' + builds: - id: witr main: ./cmd/witr @@ -60,6 +66,30 @@ nfpms: dst: /usr/share/man/man1/witr.1 file_info: mode: 0644 + - src: completions/witr.bash + dst: /usr/share/bash-completion/completions/witr + file_info: + mode: 0644 + # Debian's zsh searches vendor-completions; Fedora's and Alpine's search site-functions. + - src: completions/witr.zsh + dst: /usr/share/zsh/vendor-completions/_witr + packager: deb + file_info: + mode: 0644 + - src: completions/witr.zsh + dst: /usr/share/zsh/site-functions/_witr + packager: rpm + file_info: + mode: 0644 + - src: completions/witr.zsh + dst: /usr/share/zsh/site-functions/_witr + packager: apk + file_info: + mode: 0644 + - src: completions/witr.fish + dst: /usr/share/fish/vendor_completions.d/witr.fish + file_info: + mode: 0644 changelog: sort: asc diff --git a/README.md b/README.md index 7663f979..23260665 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ man witr Shell Completions
-`witr` supports tab completion for all flags. To enable it, add the appropriate line to your shell configuration: +`witr` supports tab completion for all flags. The deb, rpm and apk packages and the Nix flake install it for Bash, Zsh and Fish. Otherwise, add the appropriate line to your shell configuration: **Bash** ```bash diff --git a/flake.nix b/flake.nix index 0471e452..08a542d7 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,13 @@ nativeBuildInputs = [ pkgs.installShellFiles ]; postInstall = '' installManPage ./docs/cli/witr.1 + '' + # Completions come from running the built binary, which a cross build can't do. + + lib.optionalString (pkgs.stdenv.buildPlatform.canExecute pkgs.stdenv.hostPlatform) '' + installShellCompletion --cmd witr \ + --bash <($out/bin/witr completion bash) \ + --fish <($out/bin/witr completion fish) \ + --zsh <($out/bin/witr completion zsh) ''; meta = { From 96fe86fa9be53d5e9722a53ed47018c2a0c81662 Mon Sep 17 00:00:00 2001 From: Self-Perfection Date: Sat, 24 Oct 2026 02:40:05 +0000 Subject: [PATCH 2/2] docs: say what shells need to pick up packaged completions Bash only loads the packaged script through bash-completion and Zsh through compinit, so keep the manual setup as the fallback. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23260665..efa8feb3 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ man witr Shell Completions
-`witr` supports tab completion for all flags. The deb, rpm and apk packages and the Nix flake install it for Bash, Zsh and Fish. Otherwise, add the appropriate line to your shell configuration: +`witr` supports tab completion for all flags. The deb, rpm and apk packages and the Nix flake install completion scripts for Bash, Zsh and Fish. Fish picks them up as is; Bash needs the `bash-completion` package and Zsh needs `compinit` enabled, which most setups already have. Otherwise, or when installed another way, add the appropriate line to your shell configuration: **Bash** ```bash