Note: This project enables intelligent, context-aware command completion in PowerShell using AI models via the OpenRouter/OpenApi API.
This script provides advanced auto-completion for PowerShell commands by leveraging AI (Google Gemini) through the OpenRouter/OpenApi API. It enhances the PowerShell experience with two interactive completion modes:
- Interactive Menu (Ctrl+Spacebar): Displays AI-powered suggestions in a navigable CLI menu.
- Inline ListView (Ctrl+!): Shows suggestions inline, allowing navigation with Tab/Shift+Tab.
- AI-Driven Suggestions: Context-aware completions for partial PowerShell commands.
- Multiple Completion Modes: Choose between menu or inline list view.
- Customizable Key Bindings: Easily trigger suggestions and navigate options.
- Best Practice Recommendations: Suggestions promote PowerShell best practices and valid syntax.
- OpenAPI-Compatible: Works with any OpenAPI-style AI endpoint supporting chat/completions.
# Prerequisites
- PowerShell 5.1 or later
- PSReadLine module
- OpenRouter/OpenApi API key (set as OPEN_ROUTER_API_KEY environment variable)
# Usage
.\Get-IACompletion.ps1To enable AI auto-completion in every PowerShell session, add the following line to your PowerShell profile ($PROFILE):
if (Test-Path "$HOME\Documents\PowerShell\Get-IACompletion.ps1") {
. "$HOME\Documents\PowerShell\Get-IACompletion.ps1"
}This ensures the script is loaded automatically each time you start PowerShell.
### Key Bindings
| Key | Action |
|------------------|---------------------------------------------|
| Ctrl+Spacebar | Open interactive AI suggestion menu |
| Ctrl+! | Show inline AI suggestions (ListView style) |
| Tab/Shift+Tab | Cycle through suggestions |
| Enter | Accept selected suggestion |
| Esc | Cancel suggestions / restore original line |
---
## Configuration
- **API Key:** Set your OpenRouter/OpenApi API key as the `OPEN_ROUTER_API_KEY` environment variable.
- **Model:** Default is `google/gemini-2.5-flash-lite`. You can change `$global:Model` for other supported models.
- **Endpoint:** Uses `https://openrouter.ai/api/v1/chat/completions` by default. Update if using a different OpenAPI-compatible service.
---
## Examples
```powershell
# Get AI completions for a partial command
Get-IACompletion "Get-Child" 5
Tip
For best results, ensure your API key is valid and you have internet connectivity.
Important
The AI suggestions never repeat your input—they only provide the text to add for completion.
Get-IACompletion.ps1— Main script with all logic and key bindings
- For API details, see OpenRouter API Docs
- For PowerShell module info, see PSReadLine
Developed by Heni FAZZANI