Skip to main content

Creates shell command from a description using an LLM

Project description

nlshell

A very small Python package that generates shell commands from a "natural language" description. It will provide a explanation of the command and prefill the command line with the generated command.

You must provide a url to an openai compatible api, e.g. a local model served by e.g. Ollama, or a remote model.

⚠️ IMPORTANT! Never run a generated command without understanding what it does. The generated command may be harmful. There is no guarantee whatsoever that what the LLM suggests is correct! DON'T BLINDLY TRUST THE GENERATED SUGGESTION!

Table of Contents

Installation

Install nlshell from PyPI with either pip or uv.

# Using pip
pip install nlshell

# Using uv
uv tool install nlshell

Development

To run the test suite with the project-managed environment:

uv sync --group dev
uv run pytest -q

Usage

Activate the virtual environment where the package is installed to use the nlshell command.

Set the base_url

The package uses the openai client to call an LLM. By specifying a base-url you can use your own model, e.g. a local model.

c --base-url http://localhost:11434/v1

If no base_url is explicitly set, the package will ask which url to use.

Create a command

c list all files in the current directory, including hidden files

where c is the nlshell command. This command will generate a response like this:

The 'ls' command lists directory contents. The option '-l' provides a long listing format which includes file permissions, number of links, owner, group, size, and time of last modification. The '-a' option ensures hidden files (those starting with a dot .) are also listed.
$ ls -la

Set the API key

export NLSHELL_API_KEY="your-api-key"

The API key is read from the NLSHELL_API_KEY environment variable only. It is not stored in ~/.config/nlshell/settings.ini.

Even if you run a local model you may need to set an API key since the OpenAI client requires one, even if the key is just a dummy value.

Set the model

c --set-model qwen3:8b

If no model is specified the package will ask which model to use.

Switch between local and open-router models

You can easily switch between using a local model (via Ollama) or an open-router remote model:

# Use local model
c --use-local

# Use open-router remote model
c --use-open-router

The setting is saved to ~/.config/nlshell/settings.ini and persists between sessions. Defaults to local mode.

Use from any environment

If you have installed the package in a virtual environment you can use it from any environment by adding a simple shell script to e.g. ~/.local/bin:

  1. Create a file ~/.local/bin/c with the following content:

    #!/bin/bash
    # Activate the venv and run the command from it
    source /path/to/your/environment/.venv/bin/activate
    exec c "$@"
    
  2. Make the script executable:

    chmod +x ~/.local/bin/c
    

Now you can use the c command from any terminal session.

License

Distributed under the MIT License. See LICENSE for more information.

GitHub

https://github.com/mbrycke/nlshell

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

nlshell-0.1.2.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

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

nlshell-0.1.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nlshell-0.1.2.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nlshell-0.1.2.tar.gz
Algorithm Hash digest
SHA256 da0a004dee40a9012ab580adbe6f1f5e2435bcb4c44345197803e1ca3a2e647d
MD5 d5bc379b014b21445efdc6d394ef266f
BLAKE2b-256 c2c72a56783ceff862a85625447a410fe6090711a9d012218f6c7c14b19f1899

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nlshell-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nlshell-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d9524fc5f93e03a9c0644aa46f2dd40e9a80f0aef2cf5a9ba6c3216d3e01dc89
MD5 5fbf6e0ff5d46be359fe1fbe0f416e77
BLAKE2b-256 60679bc5ad6532c369dded2e0a30809d17298b68aad6b4534950a0c3e45103bb

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