Skip to content

feat: shell completions — bash, zsh and fish#81

Merged
shouze merged 10 commits intomainfrom
feat/shell-completions
Mar 4, 2026
Merged

feat: shell completions — bash, zsh and fish#81
shouze merged 10 commits intomainfrom
feat/shell-completions

Conversation

@shouze
Copy link
Contributor

@shouze shouze commented Mar 4, 2026

Closes #79

What changed

completions subcommand

New CLI subcommand that prints a shell completion script to stdout:

github-code-search completions               # auto-detects shell from $SHELL
github-code-search completions --shell fish  # explicit

Supported shells: bash, zsh, fish.

Auto-install via install.sh

After installing the binary, install.sh now calls install_completions() which:

  • detects the current shell
  • writes the completion file to the standard location for that shell
  • respects XDG_CONFIG_HOME, XDG_DATA_HOME, ZDOTDIR overrides
  • prints instructions for unknown shells
Shell Default path
fish ~/.config/fish/completions/github-code-search.fish
zsh ~/.zfunc/_github-code-search
bash ~/.local/share/bash-completion/completions/github-code-search

Auto-refresh via upgrade

After a successful upgrade, completions are refreshed in-place only if the file already exists (opt-in — never creates from scratch):

✓ Shell completions refreshed at ~/.config/fish/completions/github-code-search.fish

Tests

  • 34 TypeScript unit tests for generateCompletion(), detectShell(), getCompletionFilePath(), refreshCompletions()
  • 15 bats tests for install_completions() covering fish/zsh/bash/unknown shell + XDG overrides
  • New test:bats script in package.json

CI

  • Merged test + quality jobs to avoid duplicate checkout/setup-bun/install steps
  • Added test-bats job: installs bats via npm install -g bats (not pre-installed on Ubuntu runners), then runs bats install.test.bats

How to test manually

# Generate and inspect a completion script
./dist/github-code-search completions --shell fish
./dist/github-code-search completions --shell zsh
./dist/github-code-search completions --shell bash

# Simulate install.sh completion install
SHELL=/usr/bin/fish bash install.sh   # (requires network — downloads binary)

# Run bats tests locally
bats install.test.bats

- 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
Copilot AI review requested due to automatic review settings March 4, 2026 20:01
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

… 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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 completions subcommand that prints bash/zsh/fish completion scripts to stdout.
  • Updates install.sh to 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.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

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
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Coverage after merging feat/shell-completions into main will be

96.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts97.50%100%100%97.18%52, 60
   api.ts93.43%100%100%92.51%235–239, 295, 312, 63–69
   cache.ts98.08%100%100%97.87%28
   completions.ts99.35%100%100%99.29%252
   group.ts100%100%100%100%
   output.ts99.12%100%94.74%99.52%58
   render.ts93.11%100%84.62%93.49%100, 102–104, 106–107, 134, 298–299, 342–345, 76, 95–99
   upgrade.ts88.06%100%94.12%87.50%122–123, 143–150, 153–159, 164, 169, 205–208
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts99.29%100%100%99.01%184–185
   rows.ts97.87%100%100%97.73%54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%

@shouze shouze merged commit d7d1c0a into main Mar 4, 2026
6 checks passed
@shouze shouze deleted the feat/shell-completions branch March 4, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: shell completions — bash, zsh and fish (v1.7.0)

2 participants