A command-line tool that converts natural language into shell commands using LLMs via Ollama. This tool makes it easier to execute complex shell commands by describing what you want to do in plain English.
- 🤖 Natural language to shell command conversion
- 🛡️ Advanced safety checks for potentially dangerous commands
- 📝 Command history with search functionality
- 🎨 Colorized output for better readability
- 🔧 Configurable model selection
- ✅ Interactive command confirmation
- 🚫 Protection against destructive operations
- 🔍 Detection of recursive and privileged operations
The tool includes multiple layers of protection:
- Command Validation: Checks for dangerous patterns like:
- Destructive commands (
rm -rf,dd, etc.) - System file operations
- Recursive operations
- Privilege escalation
- Dangerous
findcommands
- Destructive commands (
- Interactive Confirmation: Always asks for confirmation before execution
- History Tracking: Maintains a log of all commands for auditing
- Special Character Handling: Properly escapes special characters in input
- Warning System: Color-coded warnings for different types of dangerous operations
- Ollama installed and running
jqcommand-line JSON processorcurlfor API communication- Zsh shell
- Make the script executable:
chmod +x ai.sh- (Optional) Add it to your PATH for global access:
sudo ln -s "$(pwd)/ai.sh" /usr/local/bin/term-llm./ai.sh "your prompt describing what you want to do"For example:
./ai.sh "list all PDF files in the current directory"View your command history:
./ai.sh --historySearch through history:
./ai.sh --history "pdf"Clear history:
./ai.sh --clear-historySpecify a different model:
./ai.sh -m "llama3.1:16b" "your prompt"Or set a default model via environment variable:
export TERM_LLM_MODEL="llama3.1:16b"
./ai.sh "your prompt"View help message:
./ai.sh --helpThe tool will warn you about potentially dangerous operations:
- Destructive Commands: Commands that could delete or overwrite data
- System Operations: Commands that affect system files or directories
- Recursive Operations: Commands that operate recursively on directories
- Privileged Operations: Commands that require elevated privileges
When a dangerous command is detected:
- The command is displayed with a warning
- The original prompt is shown
- The specific dangerous pattern is identified
- You're advised to type the command manually if absolutely necessary
- The tool takes your natural language prompt
- Sanitizes the input to handle special characters
- Sends it to Ollama with a system prompt to generate shell commands
- Validates the generated command for safety
- Displays the command and asks for confirmation
- If confirmed, executes the command
- Stores the interaction in history
Command history is stored in ~/.term_llm/history.txt with the following format:
timestamp | original prompt | generated command
Feel free to submit issues and enhancement requests!
This project is open source and available under the MIT License.