Skip to content

Fazzani/AI-Auto-Completion-PowerShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

AI-Powered Auto-Completion for PowerShell

Note: This project enables intelligent, context-aware command completion in PowerShell using AI models via the OpenRouter/OpenApi API.


Overview

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.

Features

  • 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.

Quick Start

# Prerequisites
- PowerShell 5.1 or later
- PSReadLine module
- OpenRouter/OpenApi API key (set as OPEN_ROUTER_API_KEY environment variable)

# Usage
.\Get-IACompletion.ps1

Integrate with PowerShell Profile

To 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

Admonitions

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.


Project Structure

  • Get-IACompletion.ps1 — Main script with all logic and key bindings

Support & Documentation


Author

Developed by Heni FAZZANI

About

This project enables intelligent, context-aware command completion in PowerShell using AI models via the OpenRouter/OpenApi API.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors