Skip to main content

AI-powered CLI for generating and executing shell commands

Project description

Project Overview

Project Purpose

Termai is a command-line tool that translates natural language instructions into shell commands using the power of AI. It aims to make interacting with your terminal more intuitive and efficient by automating command generation and reducing the need to memorize complex syntax. Think of it as having an AI assistant that helps you navigate the command line.

Key Features

  • Natural Language to Shell Command Conversion: Translates your plain English instructions into executable shell commands using the Gemini language model.
  • Command Review: Allows you to review the generated command(s) before execution, ensuring accuracy and preventing unintended actions.
  • Command Execution: Executes the generated commands directly from the tool, capturing and displaying the output in a user-friendly format.
  • Shell Detection: Automatically detects your shell environment (bash, zsh, powershell, etc.) to ensure compatibility.
  • Command Validation: Implements basic security measures by validating commands against a list of potentially dangerous patterns.

Architecture

Termai's core functionality revolves around the cli.py script, which acts as the command-line interface. When you provide an instruction, cli.py uses the get_shell_command function to leverage the Gemini model (via langchain_google_genai) to generate the corresponding shell command(s). Before execution, the generated command is validated using the validate_command function from utils.py to prevent potentially harmful commands from running. Finally, the execute_command function executes the command(s), captures the output, and displays it to you. The setup.py file manages the project's dependencies and packaging.

Technical Stack

  • Python: The primary programming language.
  • Typer: Used for building the command-line interface.
  • Pydantic: Used for data validation and settings management.
  • Rich: Used for creating visually appealing output in the terminal.
  • google-generativeai & langchain-google-genai: Used to interact with the Gemini language model.
  • python-dotenv: Used for managing environment variables.
  • setuptools: Used for packaging and distributing the project.
  • subprocess: Used for executing shell commands.
  • Design Patterns: Pydantic models are used for data validation.

Getting Started

  1. Clone the repository: git clone <repository_url>
  2. Navigate to the project directory: cd termai
  3. Install the dependencies: pip install . (This uses setup.py to install the necessary packages)
  4. Configure your Gemini API key: Set the GOOGLE_API_KEY environment variable. You can do this by creating a .env file in the project root and adding GOOGLE_API_KEY=YOUR_API_KEY.
  5. Run the tool: termai "Your instruction here" -e

Project Structure

termai/
├── src/
│   ├── cli.py       # Command-line interface logic
│   ├── utils.py     # Utility functions (command validation, shell detection)
│   └── __init__.py
├── try.py         # Script for creating a new Next.js application (example)
├── setup.py       # Build script for packaging and distribution
└── README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termai_cli-0.5.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termai_cli-0.5.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file termai_cli-0.5.0.tar.gz.

File metadata

  • Download URL: termai_cli-0.5.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for termai_cli-0.5.0.tar.gz
Algorithm Hash digest
SHA256 adbd2c7dd6e8b51617c77f4bcfaba6346108f44a09f37adfbc7092827b164828
MD5 1dbef47cbf19a16b02ac8e1b968c2f73
BLAKE2b-256 5d5848582677a10c99ea6cdd988f12e9b0ad40f3dcfd4c48855230739ebb9f30

See more details on using hashes here.

File details

Details for the file termai_cli-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: termai_cli-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for termai_cli-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29fc1462f66cfb4a8a5ab59979ed93c8179e993977242d5cbb0a130ac72d3a53
MD5 a92f4cd02c5919b0d029a768190820f6
BLAKE2b-256 005d35452da73b6c0170595cd80735f814e1bf3ec6fa9a16b61969c3a8ac22ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page