This plugin provides a Zsh completion and command expansion widget for natural language shell command generation using OpenAI-compatible APIs.
- Type
AI <your request>and press TAB to replace your buffer with a shell command generated by OpenAI. - Supports multi-line command output, joining them with
;. - Works with OpenAI and Azure OpenAI compatible APIs.
curljq- An OpenAI API key (set as the
OPENAI_API_KEYenvironment variable)
-
Copy the script
Placezsh-completions/_aiin a directory included in your$fpath, e.g.~/.zsh/completions. -
Add to your fpath
In your.zshrc, add:fpath=(~/.zsh/completions $fpath) -
Set your API key
Export your OpenAI API key in your.zshrc:export OPENAI_API_KEY=sk-... -
Reload your shell
Restart your terminal or run:source ~/.zshrc
-
Type:
AI <describe your shell task>and press TAB.
-
The buffer will be replaced with the generated shell command(s).
- To use a different keybinding, change the
bindkeyline at the end of the script. - You can set
OPENAI_API_BASE,OPENAI_API_URL, orOPENAI_MODELto customize the API endpoint or model.
- If no command is generated, check
~/.ai_last_response.jsonfor the raw API response. - Ensure your API key is valid and you have network connectivity.
MIT License