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..efa8feb3 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 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 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 = {