A ZSH plugin that uses Ollama to analyze command execution and provide instant AI-powered feedback when commands fail or produce unexpected results.
- 🔍 Automatically monitors command execution
- ❌ Detects failed commands and non-zero exit codes
- 🤖 Provides AI-powered analysis using Ollama
- ✨ Clean, colorized output in your terminal
- ⚡ Lightweight and fast (only analyzes when needed)
- ZSH shell
- Ollama installed and running
- A compatible Ollama model (default: llama3.2)
-
Install Ollama:
macOS/Linux:
curl -fsSL https://ollama.ai/install.sh | sh
-
Start Ollama service
ollama serve
-
Pull the default model:
ollama pull llama3.2
-
Install the plugin:
Create plugins directory if it doesn't exist
mkdir -p ~/.zsh/plugins
Clone this repository
git clone https://github.com/yourusername/command-ai-assistant.git cp command-ai-assistant/last-command.plugin.zsh ~/.zsh/plugins/
-
Add to your
~/.zshrc
:source ~/.zsh/plugins/last-command.plugin.zsh
-
Reload your shell:
source ~/.zshrc
Simply use your terminal as normal. The plugin will automatically:
- Monitor command execution
- Show exit codes
- Provide AI analysis for failed commands
Example output:
$ ls /nonexistent
ls: cannot access '/nonexistent': No such file or directory
[14:23:47] ✗ (2) ls /nonexistent
💡 Analysis:
The command failed because the specified directory doesn't exist. Use 'ls -la' to check the current directory contents.
-------------------
You can customize the plugin by editing last-command.plugin.zsh
:
- Change the AI model:
In analyze_command function, change:
local analysis=$(ollama run llama2 "$prompt") # or any other model
- Adjust when analysis triggers:
In precmd function, modify conditions:
if [ $EXIT_CODE -ne 0 ] || [[ ${#LAST_COMMAND} -gt 10 ]]; then
# Adjust conditions here
fi
- Uses ZSH's
preexec
andprecmd
hooks to monitor commands - Captures command output and exit codes
- Sends failed commands to Ollama for analysis
- Displays formatted results in your terminal
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - feel free to use this in your own projects!
- Ollama for providing the AI backend
- ZSH community for the excellent shell hooks system
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue if needed
- Include your:
- OS version
- ZSH version
- Ollama version
- Error messages