# ohmyai AI-powered command suggestions for Zsh. Type what you want to do, press the hotkey, and get shell command suggestions from OpenAI. ## Requirements - [Oh My Zsh](https://ohmyz.sh/) - [curl](https://curl.se/) - [jq](https://jqlang.github.io/jq/) or Python 3 (fallback when API returns malformed JSON) - OpenAI API key - [fzf](https://github.com/junegunn/fzf) (optional, for fuzzy selection UI – uses first suggestion if not installed) ### Install dependencies ```bash python3 setup.py ``` This installs jq, curl, and fzf via Homebrew (macOS) or apt/dnf (Linux). The plugin will warn on load if any are missing. ## Installation ### Oh My Zsh 1. Clone into your custom plugins directory: ```bash git clone https://github.com/briques/ohmyai ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyai ``` 2. Add the plugin to your `.zshrc`: ```zsh plugins=(... ohmyai) ``` 3. Set your OpenAI API key: ```zsh export OHMYAI_OPENAI_API_KEY="sk-..." ``` 4. (Optional) Install fzf for a nicer selection UI: ```bash brew install fzf # macOS ``` ## Usage 1. Type what you want to do (e.g. `list all json files in this directory` or `git status`) 2. Press **Ctrl+o** (or your configured hotkey) 3. Select a suggestion (fzf menu or numbered list) 4. The command is inserted into your buffer ## Configuration Set these in your `.zshrc` before Oh My Zsh loads: | Variable | Default | Description | |----------|---------|-------------| | `OHMYAI_OPENAI_API_KEY` | (required) | Your OpenAI API key | | `OHMYAI_HOTKEY` | `^o` (Ctrl+o) | Keybinding to trigger suggestions | | `OHMYAI_MODEL` | `gpt-4o-mini` | OpenAI model (e.g. `gpt-4o` for better quality) | | `OHMYAI_N_SUGGESTIONS` | `5` | Max number of suggestions to show | | `OHMYAI_MAX_TOKENS` | `200` | Max tokens for API response (lower = cheaper, ~50 tokens per command) | | `OHMYAI_FZF_OPTS` | (purple theme) | fzf options for selection UI (e.g. `--border=sharp`) | ### Example ```zsh export OHMYAI_OPENAI_API_KEY="sk-..." OHMYAI_MODEL='gpt-4o' OHMYAI_N_SUGGESTIONS=8 OHMYAI_HOTKEY='^o' ``` ## Security - Never commit your API key. Use environment variables or a separate config file (e.g. `~/.zshrc.local`) that you don't share. - The plugin sends your current input and recent command history to OpenAI. History is sanitized to exclude `OHMYAI_OPENAI_API_KEY=` lines. - **If your API key was exposed** (e.g. in debug output or shared config), rotate it immediately at platform.openai.com. ## License MIT