Add PowerShell tab completion support#212
Open
HeyItsGilbert wants to merge 2 commits intoiterative:mainfrom
Open
Add PowerShell tab completion support#212HeyItsGilbert wants to merge 2 commits intoiterative:mainfrom
HeyItsGilbert wants to merge 2 commits intoiterative:mainfrom
Conversation
* Add PowerShell tab completion support
Implement PowerShell as a fourth supported shell alongside bash, zsh, and
tcsh. The generated script uses Register-ArgumentCompleter -Native with a
ScriptBlock that parses the command AST, tracks parser state (subcommands,
options, positionals, nargs), and returns CompletionResult objects.
Key changes:
- Add complete_powershell() with @mark_completer("powershell") decorator
- Add get_powershell_commands() for recursive parser traversal
- Add PowerShell serialization helpers for hashtables/arrays
- Add CHOICE_FUNCTIONS entries for powershell file/dir completion
- Update examples/customcomplete.py with PowerShell preamble
- Update tests with PowerShell assertions (all 78 tests pass)
- Update README, docs/index.md, docs/use.md with PowerShell instructions
- Include PLAN-powershell-support.md documenting the architecture
Note: option-specific choices/compgens completion is stubbed with a TODO
marker for future implementation.
https://claude.ai/code/session_01F9QZN9wfoaU7gujvy9Kva9
* Implement option-specific choices/compgens in PowerShell completer
Track a $currentActionKey through the state machine that gets updated
on subparser reset, option match, and nargs exhaustion. Use it in the
completion generation section so that option-specific choices (e.g.
--shell bash/zsh/tcsh/powershell) and compgen functions are properly
completed, matching the bash implementation's behavior.
https://claude.ai/code/session_01F9QZN9wfoaU7gujvy9Kva9
* Add SHTAB_DEBUG env var for PowerShell completion debugging
When $env:SHTAB_DEBUG is set to 'true', the completer prints
the internal state (wordToComplete, prefix, actionKey, etc.)
to help diagnose completion issues.
https://claude.ai/code/session_01F9QZN9wfoaU7gujvy9Kva9
---------
Co-authored-by: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds PowerShell tab completion support to shtab, enabling native PowerShell argument completion for CLI applications built with argparse.
Key features:
Register-ArgumentCompleter -NativeChanges
shtab/init.py: Added PowerShell completer implementation with:
get_powershell_commands()for parser tree extractioncomplete_powershell()decorated completer functionCHOICE_FUNCTIONSinfrastructureDocumentation & Examples:
README.rstanddocs/index.mdto list PowerShell as supported shelldocs/use.mdexamples/customcomplete.pywith PowerShell preambleTests: Extended existing parametrized test suite to include PowerShell
Building & Testing Locally
Prerequisites
pip install -e .Run tests
Generate completion script manually
Test completion in PowerShell
Enable debug output
Set the
SHTAB_DEBUGenvironment variable to trace completion state: