Skip to main content

Convert natural language instructions to bash commands using Ollama

Project description

๐Ÿš Baish

Natural Language to Bash Commands using Ollama

Baish is a simple, elegant terminal application that converts natural language instructions into bash/linux commands using a local Ollama instance. Say goodbye to googling command syntax!

Demo License

โœจ Features

  • ๐ŸŽจ Beautiful Terminal UI - Rich, colorful interface with panels and prompts
  • ๐Ÿ”— Ollama Integration - Works with any Ollama model locally
  • โšก Dual Modes - Interactive mode or single command execution
  • ๐Ÿ›ก๏ธ Safety First - Built-in checks for potentially dangerous commands
  • ๐Ÿš€ Real-time Execution - Live command output streaming
  • ๐Ÿ“ Help System - Built-in help with -h and /help commands

๐Ÿš€ Quick Start

Prerequisites

  1. Python 3.8+ with uv package manager
  2. Ollama installed and running locally
  3. A model downloaded in Ollama (e.g., ollama pull llama3.2)

Installation

Option 1: From PyPI (Recommended)

pip install baish_assistant

Option 2: From Source

git clone https://github.com/tcsenpai/baish.git
cd baish
uv pip install -e .

Option 3: Direct Execution

git clone https://github.com/tcsenpai/baish.git
cd baish
uv pip install rich click python-dotenv requests
python main.py "show my ip address"

Configuration

Create a .env file in your project directory:

OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=llama3.2:latest

๐Ÿ“– Usage

Command Line Interface

# Single command mode
baish "show my ip address"
baish "list files in current directory"
baish "check disk usage"

# Interactive mode
baish -i

# Show help
baish -h

# Direct execution (without installation)
python main.py "find python files"
uv run python main.py -i

Interactive Mode

$ baish -i
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿš Baish - Natural Language to Bash    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

What would you like to do? > show my ip address

๐Ÿค” Thinking...

โ”Œโ”€โ”€โ”€ Generated Command โ”€โ”€โ”€โ”
โ”‚ ip addr show            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Execute this command? [Y/n]: y

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>...
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โœ“ Command completed successfully

๐ŸŽฏ Examples

Natural Language Generated Command
"show my ip address" ip addr show
"list files in current directory" ls -la
"check disk usage" df -h
"find python files" find . -name "*.py"
"stop nginx service" sudo systemctl stop nginx
"show running processes" ps aux
"check memory usage" free -h
"show network connections" netstat -tuln

๐Ÿ›ก๏ธ Safety Features

Baish includes built-in safety checks for potentially dangerous commands:

  • Pattern Detection: Identifies risky commands like rm -rf /, format, shutdown, curl | sh
  • User Confirmation: Always prompts before executing any command
  • Command Preview: Shows exactly what will be executed in a highlighted panel
  • Graceful Cancellation: Easy to cancel dangerous operations
  • Debug Mode: Optional detailed logging for troubleshooting

Dangerous patterns detected:

  • File system destruction (rm -rf /, format, mkfs)
  • System control (shutdown, reboot, init)
  • Privilege escalation risks (chmod 777, chown root)
  • Remote execution (curl | sh, wget | sh)
  • Fork bombs and system overload

โš™๏ธ Configuration Options

Environment Variables

  • OLLAMA_URL - Ollama server URL (default: http://localhost:11434)
  • OLLAMA_MODEL - Model to use (default: llama3.2:latest)
  • BASH_DEBUG - Enable debug logging (optional)

Advanced Configuration

# Use remote Ollama instance
OLLAMA_URL=http://192.168.1.100:11434

# Use a specific model variant
OLLAMA_MODEL=codellama:7b-instruct

# Enable debug output
BASH_DEBUG=1

Model Recommendations

  • Fast & Efficient: llama3.2:latest, qwen2.5:7b, phi3:mini
  • More Capable: llama3.1:8b, codellama:7b, qwen2.5:14b
  • Lightweight: tinyllama:latest, phi3:mini
  • Code-Focused: codellama:7b, deepseek-coder:6.7b

Note: Ensure your chosen model is installed in Ollama:

ollama pull llama3.2:latest

๐Ÿ—๏ธ Development

Setup Development Environment

git clone https://github.com/tcsenpai/baish.git
cd baish

# Copy and configure environment
cp .env.example .env
# Edit .env with your Ollama settings

# Install dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black .
ruff check .

Project Structure

baish/
โ”œโ”€โ”€ baish/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ main.py          # Package entry point
โ”œโ”€โ”€ main.py              # Direct execution entry point
โ”œโ”€โ”€ pyproject.toml       # Project configuration
โ”œโ”€โ”€ .env                 # Configuration file
โ””โ”€โ”€ README.md           # This file

Running Tests

pytest

Code Formatting

black .
ruff check .

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Ollama for the excellent local LLM platform
  • Rich for the beautiful terminal UI
  • Click for the CLI framework

๐Ÿ“ž Support


Made with โค๏ธ by tcsenpai

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

baish_assistant-0.1.2.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

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

baish_assistant-0.1.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file baish_assistant-0.1.2.tar.gz.

File metadata

  • Download URL: baish_assistant-0.1.2.tar.gz
  • Upload date:
  • Size: 53.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for baish_assistant-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3d7c8271b46781a064b9e07a77b27a481b9c02a1a991497d1d7cb0235c7b4f3d
MD5 a05c4258f991872944a85e7ba9a0bf78
BLAKE2b-256 ae76618cd47a7705a887e55b270d66d0481fdd37b261e4ac7c01e8dac88b4f52

See more details on using hashes here.

File details

Details for the file baish_assistant-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for baish_assistant-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 deff73704c713ac769f1141da651d11ace7fa28dd37bf3df2e1f7a3003d542a2
MD5 c8f4b7431d47c796b4eb3dd5e3c49c15
BLAKE2b-256 34c9ca941c0c446e21fd4e3fae3d5b5fc4e4261c9672e091a9cfe929f16dd882

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