A simple ZSH plugin that integrates OpenCode AI with your shell, allowing you to generate shell commands using natural language. Press Ctrl+O to transform any text in your command line into optimized shell commands.
- 🤖 AI-powered command generation using OpenCode API
- ⚡ Interactive selection with fzf for choosing between 3 ranked options
- 🎯 Ranked by best practices - speed, safety, and reliability
- 🎨 Smooth UX with animated spinner feedback
- 🔧 Easy configuration for model selection and debug output
- ⌨️ Single keybinding (Ctrl+O) for quick access
- Faster command composition - generate complex shell commands instantly
- Learn shell commands - see how experts would approach tasks
- Interactive choice - pick the best command from 3 ranked options
- No command execution - you control what gets run
This plugin requires:
- opencode - OpenCode CLI for generating commands
- fzf (optional) - For interactive command selection (defaults to first option if not installed)
Visit OpenCode documentation for installation instructions specific to your system.
# macOS with Homebrew
brew install fzf
# Linux with apt
sudo apt-get install fzf
# Or via your package manager
# https://github.com/junegunn/fzf#installationgit clone https://github.com/andreacasarin/zsh-ask-opencode.git $ZSH_CUSTOM/plugins/zsh-ask-opencodeThen add zsh-ask-opencode to the plugins array in your ~/.zshrc:
plugins=(... zsh-ask-opencode)Reload your shell:
source ~/.zshrcAdd to your ~/.zsh_plugins.txt:
andreacasarin/zsh-ask-opencode
Then run:
antidote bundleClone the repository:
git clone https://github.com/andreacasarin/zsh-ask-opencode.git ~/zsh-ask-opencodeSource it in your ~/.zshrc:
source ~/zsh-ask-opencode/zsh-ask-opencode.plugin.zshSimply type what you want to do, then press Ctrl+O:
$ list all files modified in the last 24 hours
^OThe plugin will:
- Show a spinner while asking OpenCode
- Generate 3 ranked command options
- Display an fzf menu to select your preferred command
- Insert the selected command into your command line
- You can review and press Enter to execute, or edit further
$ compress all jpg files in this directory to 50% size
^O
# Generates: convert *.jpg -quality 50% compressed.jpg
$ find all python files with more than 100 lines
^O
# Generates: find . -name "*.py" -exec wc -l {} + | awk '$1 > 100'
$ restart the docker container named web
^O
# Generates: docker restart webChange the AI model used for generation by setting ASK_OPENCODE_MODEL:
# In your ~/.zshrc (before sourcing the plugin)
export ASK_OPENCODE_MODEL="github-copilot/gpt-5-mini" # default
export ASK_OPENCODE_MODEL="github-copilot/gpt-5" # more powerfulAvailable models depend on your OpenCode configuration.
Enable debug output to see raw API responses and parsed commands:
# In your ~/.zshrc
export ASK_OPENCODE_DEBUG=1This will print:
- Raw output from OpenCode (NUL-separated format)
- Parsed command array after splitting
- Helpful for troubleshooting
Example debug output:
[ask_opencode] Raw output (NUL-separated):
1 command1
2 command2
3 command3
[ask_opencode] Parsed commands:
1 ls -lah
2 ls -la
3 ls -l
The default keybinding is Ctrl+O. To change it, add to your ~/.zshrc:
# Change keybinding to Ctrl+G instead
bindkey '^G' ask_opencodeEnsure OpenCode is installed and in your $PATH:
which opencode
# If not found, install it per OpenCode documentationCheck debug output:
ASK_OPENCODE_DEBUG=1 your_prompt_here
^OLook for error messages from OpenCode in the terminal.
If fzf is not installed, the plugin uses the first generated command by default. Install fzf to enable selection:
brew install fzf # or your package managerVerify the file is being sourced:
# For Oh My Zsh
ls -la $ZSH_CUSTOM/plugins/zsh-ask-opencode/
# For manual installation
grep "zsh-ask-opencode" ~/.zshrcThen reload:
source ~/.zshrc
exec zshContributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE for details
Created by Andrea Casarin
