Say hello to AiTerm, your new best friend for chatting with AI right from the terminal! This nifty command-line tool lets you toss natural language commands like "list files" into a slick text-based interface, powered by tview. Watch as the AI whips up the perfect terminal command (like ls) and runs it in a tmux split pane, all while keeping your conversation history scrollable and snappy. Whether you're a terminal ninja or just love a good chat, AiTerm makes AI-powered workflows a breeze!
- Natural Language Interaction: Enter commands in natural language (e.g., "list files"), and the AI generates corresponding terminal commands (e.g.,
ls) and explanations. - tmux Integration: Commands are executed in a dynamically created
tmuxpane, displayed alongside the chat interface. - Scrollable Chat History: View past conversations in a scrollable
TextView, with support for manual scrolling to review history. - Dynamic "Generating" Indicator: A visual animation in the input field ("generating.", "generating..", "generating...") shows when the AI is processing.
- Cancel Generation: Press
Ctrl+Cduring AI processing to cancel and resume input. - Configuration Management: Stores AI service details (URL, Token, Model) in
~/.aitermrc, with interactive terminal-based setup on first run. - Version Information: Use
aiterm -vto display the tool's version. - Error Handling: Validates AI configuration and handles
tmuxsession requirements gracefully.
Install AiTerm using Go:
go install github.com/aki-colt/aiterm@latestEnsure $GOPATH/bin is in your PATH:
export PATH=$PATH:$(go env GOPATH)/bin- Go: 1.22 or later
- tmux: Required for pane splitting and command execution
- Terminal: A terminal emulator supporting ANSI colors and keyboard input
- Platform: AiTerm only supports for unix-like system such as linux or macos for now.
-
Start a tmux session:
tmux
-
Run the tool:
aiterm
-
Configure AI (first run only): If
~/.aitermrcis missing or incomplete, you'll be prompted to enter:Enter AI URL: https://api.example.com/v1 Enter API Token: your-token Enter Model: gpt-4This creates
~/.aitermrc:[ai] url=https://api.example.com/v1 token=your-token model=gpt-4 -
Interact:
- Type natural language commands (e.g., "list files") in the input field.
- Press
Enterto send the command to the AI. - View AI responses and command outputs in the split
tmuxpane. - Use
Ctrl+Cto cancel AI processing. - Press
Ctrl+Qto exit.
-
Check version:
aiterm -v
Output:
aiterm version v0.1.0
The tool stores AI configuration in ~/.aitermrc locolly. Edit this file directly to update settings, or delete it to trigger the configuration prompt on next run.
Example ~/.aitermrc:
[ai]
url=https://api.example.com/v1
token=your-token
model=gpt-4
-
Clone the repository:
git clone https://github.com/yourusername/aiterm.git cd aiterm -
Install dependencies:
go mod tidy
-
Build and test:
go build -o aiterm ./aiterm
aiterm/
├── README.md
├── ai
│ ├── ai.go # request to llm
│ ├── prompt.go # prompt
│ └── tools.go # tools to check and execute commands
├── cmd
│ └── main.go # entry point, handles flags, config, and UI setup
└── terminal
│ ├── command.go # cotroller of tmux
│ ├── dialog.go # dialog ui
├── go.mod
├── go.sum
AiTerm is built with the following components:
-
Command-Line Interface:
- Uses
flagpackage to handle-vfor version display. - Checks
~/.aitermrcfor AI configuration (URL, Token, Model). - Prompts for configuration via terminal input if missing, validated using
openai-goSDK.
- Uses
-
Configuration:
- Stores settings in
~/.aitermrcusinginiformat. - Validates AI config by attempting to list models with
openai-go.
- Stores settings in
-
UI:
- Built with
tview, featuring aTextViewfor chat history and anInputFieldfor user input. - Supports scrolling (
SetScrollable(true)), dynamic "generating" animation, andCtrl+Ccancellation. - Updates are queued via
app.QueueUpdateDrawfor thread safety.
- Built with
-
tmux Integration:
- Managed by
tmux.go, which splits the terminal usingtmux split-window -P. - Sends commands to the correct pane using
send-keys, tracked via pane ID.
- Managed by
-
AI Processing:
- Uses
openai-goSDK to process input. - Runs in a goroutine with
contextfor cancellation support. - Displays results in
TextViewand executes commands intmux.
- Uses
- Add support for multiple AI providers (e.g., Anthropic, Grok).
- Implement command-line flags for configuration overrides.
- Enhance UI with color-coded messages or a status bar.
- Add unit tests for configuration and tmux logic.
- Support configuration via environment variables.
- Support windows system.
MIT License
