Skip to content

danghung1202/cli-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI-AI

Transform natural language into terminal commands using AI. Supports multiple AI providers (OpenAI, Gemini) with easy configuration management.

Features

Natural Language to Commands - Describe what you want, get the exact command
Multiple AI Providers - OpenAI (GPT-4, GPT-3.5) and Google Gemini support
Safety First - Warns about dangerous commands before execution
Edit Before Run - Review and modify commands before execution
Easy Configuration - Interactive setup and config management
Cross-Platform - Works on Windows, Linux, and macOS

Quick Installation

Windows

  1. Download setup_windows.ps1
  2. Right-click and select "Run with PowerShell"
  3. Follow the prompts

Linux / macOS

chmod +x setup_linux.sh
./setup_linux.sh

The setup script will:

  • Install Python & pipx (if needed)
  • Install cli-ai

First Time Setup

On first run, you'll be guided through an interactive setup:

  1. Choose AI Provider - Select OpenAI or Gemini
  2. Enter API Key:
  3. Select Model (optional) - Choose your preferred model

Usage

Basic Commands

cli-ai "list all docker containers"
cli-ai "find files larger than 100MB"
cli-ai "show disk usage"
cli-ai "compress all jpg files in current folder"

Configuration Management

Manage your AI providers and settings:

cli-ai --config

Configuration menu options:

  • Switch between providers (OpenAI ↔ Gemini)
  • Update API keys
  • Change models
  • Add/configure additional providers
  • View current configuration
  • Configure popup hotkey (for SSH terminal integration)

SSH Terminal Integration (Popup Command Bar)

For SSH terminals like MobaXterm, use the popup command bar:

Starting the Popup Service

cli-ai-popup

Important: On Windows, you must run PowerShell/CMD as Administrator for global hotkey support.

This starts a background service that:

  • Listens for a global hotkey (default: Ctrl+Space)
  • Shows a popup input bar when triggered
  • Converts your natural language to commands
  • Types the command directly into your active terminal window

Usage

  1. Connect to your SSH server (MobaXterm, PuTTY, etc.)
  2. Start the popup service (as Administrator): cli-ai-popup
  3. Press your configured hotkey (default: Ctrl+Space) anywhere
  4. Type your query: "check disk space"
  5. Press Enter
  6. The command (df -h) is typed directly into your terminal!

Configuring the Hotkey

To change the hotkey from the default ctrl+space:

cli-ai --config
# Select option 7: Configure popup hotkey

Example hotkey formats:

  • ctrl+space (default)
  • ctrl+shift+a
  • alt+f1
  • `ctrl+`` (backtick)
  • ctrl+alt+c
  • win+space

Note: After changing the hotkey, restart cli-ai-popup for changes to take effect.

Stopping the Service

Press Ctrl+C in the terminal where you started the service.

Interactive Flow

When you run a command, you'll see:

  1. AI Suggestion - The generated command with explanation
  2. Safety Warning - If the command is potentially dangerous
  3. Action Options:
    • y - Run the command
    • n - Abort
    • e - Edit the command before running

Supported AI Providers

OpenAI

Google Gemini

Configuration

Configuration is stored in ~/.cli-ai_config:

{
  "provider": "openai",
  "popup_hotkey": "ctrl+space",
  "openai": {
    "api_key": "sk-...",
    "model": "gpt-4o-mini"
  },
  "gemini": {
    "api_key": "...",
    "model": "gemini-pro"
  }
}

Updating

If installed via pipx:

pipx upgrade cli-ai

Or reinstall from source:

cd cli-ai
pip install -e . --force-reinstall

Examples

# File operations
cli-ai "create a backup of all .py files"
cli-ai "rename all .txt files to .md"

# System monitoring
cli-ai "show top 10 memory consuming processes"
cli-ai "check if port 8080 is in use"

# Git operations
cli-ai "show commits from last week"
cli-ai "create a new branch called feature-x"

# Docker
cli-ai "stop all running containers"
cli-ai "remove unused images"

Troubleshooting

Provider Error: Run cli-ai --config to check your configuration

Import Error: Make sure all dependencies are installed:

pip install openai rich prompt_toolkit google-genai keyboard pyautogui pywin32

Popup Service Issues:

  • On Windows, ensure you're running as Administrator
  • Verify the hotkey format is correct (e.g., ctrl+space)
  • Check that no other application is using the same hotkey

Command Not Found: Restart your terminal or run the setup script again

Requirements

  • Python 3.8+
  • Internet connection (for AI API calls)
  • API key for your chosen provider

About

Transform natural language into terminal commands using AI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors