This is a PowerShell plugin that enables you to plug and play any AI code completion model in the command line, to improve efficiency, reduce errors and optimize your workflow.
It is completely free, as it can be used with any open-source model from Ollama, like CodeLlama, or the powerful Deepseek-Coder-v2 (default for this module).
Inspired by the impressive zsh version of this extension by Tom Doerr.
# to install or update to the latest version
Install-Module -Name PoshCodex -Force
Import-Module PoshCodex -Force
# to check if it's installed properly:
Get-Module -Name PoshCodex # should display the Enter-CompletionKeybind command
# Auto-import the module on every powershell session, so you can directly use the keybind for completion:
echo "`nImport-Module PoshCodex" >> $PROFILE
Scoop is an easy-to-use command-line installer for Windows apps. You can get Scoop from here.
scoop bucket add poshcodex_bucket https://github.com/rishi255/posh_codex
scoop install PoshCodex # not case sensitive
Import-Module PoshCodex -Force
# to update the module later, you can use:
scoop update PoshCodex
# Auto-import the module on every powershell session, so you can directly use the keybind for completion:
echo "`nImport-Module PoshCodex" >> $PROFILE
# Clone the repository
git clone https://github.com/rishi255/posh_codex
cd ./posh_codex/PoshCodex/
# Install Invoke-Build and build the module
Install-Module InvokeBuild -Force
Invoke-Build -File build.ps1
# Now import the built module
Import-Module ./Output/PoshCodex/<version_number>/PoshCodex.psd1
# Now the module can be used in the current powershell session.
# Auto-import the module on every powershell session, so you can directly use the keybind for completion:
echo "`nImport-Module ./Output/PoshCodex/<version_number>/PoshCodex.psd1" >> $PROFILE
Note: The AI completion will run locally on your machine, and the below commands will download the model file.
# install ollama (visit https://ollama.com/download or install using scoop with the below commands):
scoop bucket add versions
scoop install versions/innounp-unicode
scoop install ollama
# pull the base model
ollama pull rishi255/posh_codex_model:latest
# or, create a new model tailored for your needs using Modelfile.txt
# (refer https://github.com/ollama/ollama/blob/main/docs/modelfile.md)
ollama create my_model -f .\Modelfile.txt
echo "`n$env:OLLAMA_MODEL='my_model'" >> $PROFILE
Just type a comment or partial code snippet, and hit the keybind!
See the GIF above for a demonstration.
# print hello world to the console
Hit Ctrl+Shift+O after typing the above comment
The default keybind is Ctrl+Shift+O
.
After you import the module, you can enter your own keybind.
Just type Enter-CompletionKeybind
in the terminal and record the keyboard shortcut you want to use.
The following environment variables are available for configuration:
Environment Variable | Default Value | Description |
---|---|---|
OLLAMA_MODEL |
rishi255/posh_codex_model |
The Ollama model name to use for AI completion. |
OLLAMA_HOST |
http://localhost:11434 |
The base URL of your Ollama API. |
AUTOCOMPLETE_KEYBIND |
Ctrl+Shift+O |
The keybind to use for AI completion. |
- Test basic PS plugin working with hardcoded completions
- Test plugin by comparing the generated output from my text-to-PowerShell OpenAI playground
- Publish plugin for installation through PSGallery
- Add installation instructions to README.md
- Integrate with GitHub Actions to auto-publish new versions
- Make required modules auto-install when this module is installed
- Publish plugin for installation through Scoop
- Add a way to change the hotkey for completion by reading key input:
Enter-CompletionKeybind
- Stream the output, instead of waiting for entire thing to be generated
- AND/OR Show a progress/loading indicator when inference is running
- Extra layer of validation - validate the syntax of the response PowerShell code
- Need support for inline completion (similar to Copilot on VSCode) - currently we are inserting the response on a new line
- Need to fine tune / prompt engineer the model better for this as well - currently it isn't very good at it
- Make completed text a lighter colour to show that it is only a potential solution
- For changing text colour of prediction, look at
Set-PSReadLineOption
or in that direction
- For changing text colour of prediction, look at
- Switch to chat API instead of generate
- Provide context of previous messages
- Provide context of all commands in current terminal session? Possible using PSReadLine history
- Switch from environment variables based configuration to a config file (
poshcodex.ini
)- Ensure that getting and setting config values are only done through the config file
- After this change,
Initialize-Module-On-Import
needs to callSet-CompletionKeybind
internally after reading latest value from config.
- Add proper documentation for all the functions and
Docs/about_PoshCodex.md
- Support for install using Chocolatey
- Cycle through suggestions using some modifiable keybind (e.g.
Alt+C
) - Make a website playground that lets users try this out live? Need to check feasibility.