TerminalAI: Command-line AI assistant
Project description
Terminal AI
Bring the power of AI directly to your command line!
TerminalAI is your intelligent command-line assistant. Ask questions in natural language, get shell command suggestions, and execute them safely and interactively. It streamlines your workflow by translating your requests into actionable commands.
████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗ █████╗ ██║ █████╗ ██╗
╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗██║ ██╔══██╗██║
██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗ ██║███████║██║ ███████║██║
██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚██╗██║██╔══██║██║ ██╔══██║██║
██║ ███████╗██║ ██║██║ ╚═╝ ██║██║██║ ╚████║██║ ██║███████╗ ██║ ██║██║
╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝╚═╝
Key Features
- Natural Language Interaction: Ask questions or request actions naturally.
- Intelligent Command Suggestion: Get relevant shell commands based on your query.
- Multiple AI Backends: Supports OpenRouter, Gemini, Mistral, and local Ollama models.
- Interactive Execution: Review and confirm commands before they run.
- Context-Aware: Includes OS and current directory information in prompts to the AI.
- Safe Command Handling:
- Non-stateful commands run directly after confirmation.
- Risky commands require explicit confirmation.
- Stateful commands (
cd,export, etc.) are handled safely (see below).
- Multiple Modes:
- Direct Query (
ai "..."): Get a single response and command suggestions. - Single Interaction (
ai): Ask one question, get a response, and return to the shell. - Chat Mode (
ai --chatorai -c): Persistent conversation with the AI.
- Direct Query (
- Easy Configuration:
ai setupprovides a menu for API keys and settings. - Optional Shell Integration: For seamless execution of stateful commands in direct query mode.
- Syntax Highlighting: Uses
richfor formatted output.
Installation
Option 1: Install from PyPI (Recommended)
pip install coaxial-terminal-ai
Option 2: Install from Source
git clone https://github.com/coaxialdolor/terminalai.git
cd terminalai
pip install -e .
This automatically adds the ai command to your PATH.
Quick Setup
- Install: Use one of the methods above.
- Configure API Keys: Run
ai setupand select option5to add API keys for your chosen provider(s) (e.g., Mistral, Ollama, OpenRouter, Gemini). - Set Default Provider: In
ai setup, select option1to choose which provideraiuses by default. - (Optional) Install Shell Integration: See "Handling Stateful Commands" below if you want direct execution for commands like
cdwhen usingai "...". - Start Using: You're ready!
See the Quick Setup Guide for more detailed instructions.
Usage Examples
1. Single Interaction Mode (ai): Ask one question, get an answer/commands, then return to shell.
Flags like -v or -l can be used here.
# Basic usage
ai
AI:(mistral)> how do I list files by size?
# Request a long response
ai -l
AI:(mistral)> explain the history of Unix shells in detail
2. Direct Query Mode (ai "..."): Provide the query directly. This is where most flags are useful.
# Simple query
ai "find all python files modified in the last day"
# Auto-confirm non-risky command execution
ai -y "show current disk usage"
# (Example: If AI suggests 'df -h', it will run without a [Y/n] prompt)
# Request verbose output
ai -v "explain the concept of inodes"
# Request long output
ai -l "explain the difference between TCP and UDP"
# Combine flags: Auto-confirm and Verbose
ai -y -v "create a new directory called 'test_project' and list its contents"
# (Example: If AI suggests 'mkdir test_project && ls test_project', it will run without a prompt)
3. Chat Mode (ai --chat or ai -c): Have a persistent conversation.
# Start a normal chat
ai --chat
# Or use the alias 'ai-c' if configured via shell integration setup
# ai -c
# Start chat requesting verbose responses by default
ai -c -v
AI:(mistral)> Tell me about this project.
# ... AI response ...
AI:(mistral)> how can I contribute?
# ... AI response ...
# (Type 'exit' or 'q' to quit chat)
4. Setup Menu (ai setup): Configure providers, API keys, and shell integration.
ai setup
5. Show Version (ai --version):
ai --version
# Output: TerminalAI version X.Y.Z
6. Show Help (ai --help or ai -h):
ai --help
# Output: Detailed help message
Handling Stateful Commands (cd, export, etc.)
Commands that need to change your current shell's state (like changing directory with cd or setting environment variables with export) require special handling because a child process (like the ai script) cannot directly modify its parent shell.
TerminalAI offers two ways to handle this:
1. Copy to Clipboard (Default & Safest)
- This method works in all modes (
ai,ai "...",ai --chat). - When a stateful command is suggested, TerminalAI will prompt you to copy it:
[STATEFUL COMMAND] The command 'cd /path/to/dir' changes shell state. Copy to clipboard? [Y/n]: - Press
Y(or Enter) to copy the command. - Paste (
Cmd+V/Ctrl+Shift+V) the command into your shell prompt and press Enter to run it manually.
2. Shell Integration (for ai "..." mode)
- This method enables direct execution of stateful commands, but only when using the Direct Query mode (
ai "..."). It does not work for the interactiveaiorai --chatmodes. - How it works: It installs an
aishell function that wraps theaicommand. When you runai "query", this function runs the script in a special mode (--eval-mode), captures the confirmed command, and executes it using the shell'sevalcommand. - Installation:
- Run
ai setup. - Choose option
7("Install ai shell integration"). - Restart your shell or source your config file (e.g.,
source ~/.zshrc).
- Run
- Usage: Simply run
ai "change to parent directory". If you confirmcd .., it will execute directly in your shell.
Contributing & Feedback
Suggestions, bug reports, and contributions are welcome! Please feel free to:
- Open an issue on GitHub.
- Contact the author via email (you can find the email on the GitHub profile).
Disclaimer
TerminalAI is provided as-is without any warranties. Use at your own risk.
Always review commands suggested by the AI before executing them, especially those marked as [RISKY] or [STATEFUL]. The developers are not responsible for any data loss, system damage, or other issues that may arise from using this tool.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coaxial_terminal_ai-0.2.6.tar.gz.
File metadata
- Download URL: coaxial_terminal_ai-0.2.6.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d41a365e6638c3e35879f34e34d377428413d24495a2863737039e39fe728b
|
|
| MD5 |
ae5721a033a11ae0aa8c4830fdb1b2ee
|
|
| BLAKE2b-256 |
ffb06bacf60e2f9f8aa88b2f15b28f54c64d8ffad739a5eb8984c4a42d1a7b64
|
File details
Details for the file coaxial_terminal_ai-0.2.6-py3-none-any.whl.
File metadata
- Download URL: coaxial_terminal_ai-0.2.6-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b47d5bc82073bce4d5c5245715081d9172e5ca995d705007322e19b56442f3cc
|
|
| MD5 |
076b03e076c3d869bbd2d755ed60f238
|
|
| BLAKE2b-256 |
e63e05b1df3992be8d1c0654e357035d14a45559d1327ba3a4145c6089e6e569
|