Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ result
# Ignore build artifacts
dist/
pkg-dist/
completions/
30 changes: 30 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ man witr
<summary><strong>Shell Completions</strong></summary>
<br>

`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
Expand Down
7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading