feat: shell completions — bash, zsh and fish#81
Conversation
- Add \`completions\` subcommand: prints shell completion script to stdout - Auto-detects shell from $SHELL when --shell flag is omitted - Add \`getCompletionFilePath()\` pure helper (respects XDG_CONFIG_HOME, XDG_DATA_HOME, ZDOTDIR) - Refresh completions automatically after a successful \`upgrade\` (opt-in: only if the file already exists) - Install completions from \`install.sh\` using the installed binary - Add bats tests for \`install_completions()\` (fish, zsh, bash, unknown shell, XDG overrides) - Add \`test:bats\` script to package.json - Add \`test-bats\` job to CI (installs bats via npm, runs install.test.bats) - Merge CI \`test\` + \`quality\` jobs to avoid duplicate checkout/setup steps
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
… block - Replace 'npm install -g bats' with bats-core/bats-action@4.0.0 to install the official bats-core release (the npm 'bats' package is outdated/unrelated) - Add github-token input to avoid GitHub API rate limits during bats setup - Add shell: bash to the bats test step for explicit interpreter - Move set -euo pipefail inside the main installation block in install.sh: previously it ran at source time, modifying the shell options of the bats runner process and causing test failures
There was a problem hiding this comment.
Pull request overview
Adds first-class shell completions support to the github-code-search CLI, plus installation/refresh automation and CI coverage to keep the scripts correct over time.
Changes:
- Introduces a
completionssubcommand that prints bash/zsh/fish completion scripts to stdout. - Updates
install.shto auto-install completion files (with XDG/ZDOTDIR support) and adds bats tests for the installer behavior. - Adds upgrade-time completion refresh (opt-in: only updates if a completion file already exists) and CI workflow updates to run both TS and bats tests.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/completions.ts |
Implements completion script generators, shell detection, and canonical completion file paths. |
src/completions.test.ts |
Adds unit tests for script generation, $SHELL detection, and path resolution. |
github-code-search.ts |
Wires in the new completions subcommand and refreshes completions after upgrade. |
src/upgrade.ts |
Adds refreshCompletions() to overwrite existing completion files in-place. |
src/upgrade.test.ts |
Adds unit tests covering refresh behavior and debug logging. |
install.sh |
Adds install_completions() and calls it after installing the binary. |
install.test.bats |
Adds bats coverage for completion installation across shells + env overrides. |
.github/workflows/ci.yaml |
Merges TS test/quality steps and adds a bats test job. |
package.json |
Adds test:bats script. |
knip.json |
Ignores the bats binary for dead-code tooling. |
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GitHub Actions runners have XDG_CONFIG_HOME and XDG_DATA_HOME already set, which caused getCompletionFilePath() to ignore the injected homeDir and resolve fish/bash completion paths against the runner's XDG dirs instead of the test's temp directory. - completions.test.ts: save/clear/restore XDG_CONFIG_HOME, XDG_DATA_HOME and ZDOTDIR in beforeEach/afterEach around the getCompletionFilePath describe block - upgrade.test.ts: same isolation for the refreshCompletions describe block - install.test.bats: move 'unset XDG_CONFIG_HOME XDG_DATA_HOME ZDOTDIR' from teardown() to setup() so the first test is also protected
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…in permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…diagrams and CLI reference
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging feat/shell-completions into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Closes #79
What changed
completionssubcommandNew CLI subcommand that prints a shell completion script to stdout:
Supported shells: bash, zsh, fish.
Auto-install via
install.shAfter installing the binary,
install.shnow callsinstall_completions()which:XDG_CONFIG_HOME,XDG_DATA_HOME,ZDOTDIRoverrides~/.config/fish/completions/github-code-search.fish~/.zfunc/_github-code-search~/.local/share/bash-completion/completions/github-code-searchAuto-refresh via
upgradeAfter a successful
upgrade, completions are refreshed in-place only if the file already exists (opt-in — never creates from scratch):Tests
generateCompletion(),detectShell(),getCompletionFilePath(),refreshCompletions()install_completions()covering fish/zsh/bash/unknown shell + XDG overridestest:batsscript inpackage.jsonCI
test+qualityjobs to avoid duplicate checkout/setup-bun/install stepstest-batsjob: installsbatsvianpm install -g bats(not pre-installed on Ubuntu runners), then runsbats install.test.batsHow to test manually