Skip to content

Powershell auto completion - #645

Open
nehemiaharchives wants to merge 8 commits into
ajalt:masterfrom
nehemiaharchives:powershell
Open

Powershell auto completion#645
nehemiaharchives wants to merge 8 commits into
ajalt:masterfrom
nehemiaharchives:powershell

Conversation

@nehemiaharchives

@nehemiaharchives nehemiaharchives commented Jun 30, 2026

Copy link
Copy Markdown

Hi, I'm author of bbl - a command line tool to read and search Bible.
bbl is build based on clikt and it provides autocompletion feature for bash, zsh, and fish for macOS and linux.
bbl is kotlin/native program which targets macosArm64, macosX64, linuxX64 and mingwX64.
Only the missing part for mingwX64 was powershell autocompletion support, so I forked clikt and made PowershellCompletionGenerator.kt working.
The powershell autocompletion support includes PowershellCompletionTest.kt in my fork of clikt repo and it passes.
But in addition to that, on bbl repo side, we implemented unit test and E2E test.
bbl E2W test is done by compiled and linked Kolint/Native executable binary using script input/output testing utilizing TabExpansion2.
E2E test is run by test kitchen and latest CI result for the powershell test can be found in github action of bbl

And finally, bbl v2.0 is released with powershell completion support included, so anyone who wants to test it out can test by installing bbl on windows:

with scoop:

scoop bucket add bbl https://github.com/nehemiaharchives/bbl-scoop-bucket
scoop install bbl

or msi installer

Then run following:

$profileDir = Split-Path -Parent $PROFILE
$completion = Join-Path $profileDir "_bbl.ps1"
New-Item -ItemType Directory -Force -Path $profileDir
bbl generate-completion powershell | Out-File -Encoding utf8 -FilePath $completion
Add-Content -Path $PROFILE -Value ". `"$completion`""
. $completion

Then bbl s tab tab will auto-complete bbl search

- Filter option names, fixed candidates, and fallback completions with
  Where-Object for proper partial-input narrowing
- Add PowerShell docs to CompletionCandidates.kt KDoc and autocomplete.md
- Accept "powershell" only in CompletionGenerator.kt (not "pwsh")
…ings, correct context routing

Three bugs fixed:
1. Multiple Register-ArgumentCompleter -Native blocks consolidated into a
   single block with switch -Wildcard dispatch based on joined command-path.
   PowerShell only keeps the LAST registered block per command name, so the
   old per-subcommand-block approach meant deeper blocks overrode shallower
   ones and all non-root guards were dead code.

2. Context guard conditions fixed: old code used \[0] -ne 'bbl'
   but the loop starts at i=1 (skipping CommandElements[0]=command name), so
   \[0] is the first subcommand, never 'bbl'. Replaced with
   switch -Wildcard on \ = \ -join ' ' with exact-then-
   wildcard ordering (deepest first).

3. [CompletionResult]::new() replaced with plain strings for -Native switch
   compatibility in PowerShell 7.6.2. The -Native flag requires ScriptBlock
   to return strings (auto-converted to CompletionResult objects).

Also adds wildcard cases ('config *') for partial/unknown subcommand typing
so that e.g. 'bbl c<TAB>' still suggests root-level completions filtered
by 'c*'.
Comment thread jitpack.yml Outdated
Comment on lines +1 to +7
jdk:
- openjdk17
before_install:
- sdk install java 17.0.1-open
- sdk use java 17.0.1-open
install:
- ./gradlew publishToMavenLocal --exclude-task test -PRELEASE_SIGNING_ENABLED=false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi! I don't think this is related to this PR. You might want to remove it so the maintainer can focus on the completion feature.

@nehemiaharchives nehemiaharchives Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed in 8263465 forgot to do that before submitting PR. Thank you for finding it out!

@joffrey-bion

Copy link
Copy Markdown

Thanks a lot for this! I'm really looking forward to it! ❤️

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.

2 participants