Skip to content
/ nlsh Public

A command-line tool that converts natural language instructions into shell commands using LLM model.

License

Notifications You must be signed in to change notification settings

abakermi/nlsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Natural Language Shell (nlsh)

Build Status Release Go Version

A command-line tool that converts natural language instructions into shell commands using OpenAI's GPT model. Simply describe what you want to do in plain English, and nlsh will generate and execute the appropriate shell command.

Features

  • 🧠 Natural language to shell command conversion
  • 🛡️ Built-in safety checks for dangerous commands
  • ⚙️ Configurable settings via .nlshrc
  • 🎨 Colored output for better readability
  • 📝 Command history and context awareness
  • 🔄 Interactive and single command modes
  • 🔒 Confirmation for potentially dangerous operations

Prerequisites

  • Go 1.21 or later
  • OpenAI API key

Installation

Option 1: Quick Install

Install directly using curl:

curl -fsSL https://raw.githubusercontent.com/abakermi/nlsh/master/install.sh | bash

Option 2: Go Install

go install github.com/abakermi/nlsh@latest

Option 3: Manual Installation

  1. Clone the repository:
    git clone https://github.com/abakermi/nlsh.git
    cd nlsh
  2. Set your OpenAI API key as an environment variable:
    export OPENAI_API_KEY='your-api-key-here'
  3. Run the installation script:
    ./install.sh
  4. Restart your terminal or source your shell configuration:
    source ~/.zshrc  # or source ~/.bashrc

Usage

Set your OpenAI API key:

export OPENAI_API_KEY='your-api-key-here'

Interactive Mode

nlsh

Single Command Mode

nlsh "list all files in current directory"

Examples

# List files
nlsh "show me all hidden files"

# Git operations
nlsh "commit all changes with message 'update readme'"

# Docker operations
nlsh "show all running containers"

Safety Features

  • Command confirmation before execution
  • Configurable allowed/denied commands
  • Pattern-based command filtering
  • Protection against dangerous operations

Default configuration includes:

[safety]
confirm_execution = true
allowed_commands = [
    "ls *",
    "touch *",
    "mkdir *",
    "echo *",
    "cat *",
    "cp *",
    "mv *",
    "git *",
    "docker *",
    "code *",
    "vim *",
    "nano *"
]
denied_commands = [
    "rm -rf /*",
    "rm -rf /",
    "dd if=/dev/*",
    "mkfs.*",
    "> /dev/*",
    "shutdown *",
    "reboot *",
    "halt *",
    "*--no-preserve-root*"
]

You can customize nlsh's behavior by creating a .nlshrc file in your home directory. The configuration file supports TOML format. Here's an example of a .nlshrc file:

License

This project is open source and available under the MIT License.

About

A command-line tool that converts natural language instructions into shell commands using LLM model.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published