Skip to main content

lex the hacker

I prefer to be called a hacker.

It's a UNIX system! I know this!

Describe what you want in plain English, and lex writes the shell command for you.

$ lex "search the dir for 'xyz'"
$ grep -rn 'xyz' .

While lex thinks, you get a spinner. Then it shows the command with a short explanation of how it works, and offers it to you — pick it (just press Enter) to copy it to your clipboard:

╭──────────────────────────────────────────────────╮
│ grep -rn 'xyz' .                                 │
│                                                  │
│ Searches every file under the current directory  │
│ for the text "xyz", printing each match with its │
│ file name and line number.                       │
╰──────────────────────────────────────────────────╯
? copy to clipboard? (Use arrow keys)
 » grep -rn 'xyz' .
   skip

✓ copied to clipboard

Either way, the command also lands on your command line, ready to run.

It never executes anything itself. You always read the command and press Enter (or edit it, or throw it away). Nothing runs without you.

On typing. Putting text on your prompt uses the TIOCSTI ioctl, which current Linux kernels disable by default (dev.tty.legacy_tiocsti = 0) because it was a privilege-escalation vector. When it's unavailable — a hardened kernel, no terminal, a pipe — or when the command spans more than one line, the command simply doesn't land on your prompt. That's a normal outcome, not an error: it's still right there in the panel, and on your clipboard. Either way, lex never presses Enter for you.

Install

pip install lex-the-hacker

This gives you the lex command.

Configuration

lex talks to any OpenAI-compatible chat API — hosted OpenAI, or a local Ollama server. Point it at one with three environment variables:

Variable Required What it is
LEX_MODEL yes The model name to request, e.g. gpt-4o-mini or llama3.1.
LEX_API_KEY yes The API key. Ollama ignores it, but the client still requires a non-empty value — ollama works fine.
LEX_BASE_URL no Base URL of the endpoint. Defaults to OpenAI's hosted API.

Hosted OpenAI:

export LEX_MODEL=gpt-4o-mini
export LEX_API_KEY=sk-...

A local Ollama server:

export LEX_MODEL=llama3.1
export LEX_API_KEY=ollama
export LEX_BASE_URL=http://localhost:11434/v1

lex also tells the model which shell you're in, so the command it writes matches your shell's syntax. Run lex shell to see what it detected.

Clipboard on Linux. Copying first tries your system clipboard via pyperclip, which on Linux needs one of xclip, xsel, or wl-clipboard installed. Without one, lex falls back to OSC 52 — asking your terminal itself to set the clipboard, no install needed — which modern terminals (VS Code, kitty, alacritty, WezTerm, iTerm2, foot, …) support, even over SSH. If neither route works, the copy is skipped quietly.

Usage

Call lex with a description of what you want to do, in quotes:

$ lex "find every python file changed in the last week"

lex puts its best guess on your prompt:

$ find . -name '*.py' -mtime -7

From there it's your command like any other — run it, tweak it, or clear the line and try a different description.

More examples:

$ lex "undo my last git commit but keep the changes"
$ git reset --soft HEAD~1

$ lex "compress this folder into a tar.gz"
$ tar -czf folder.tar.gz folder/

$ lex "show what's listening on port 8080"
$ lsof -i :8080

Why you're always safe

lex only ever writes a command to your shell. It doesn't run it, and it can't run it — executing is up to you. So if a suggestion looks wrong, you'll see it before anything happens.

Download files

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

Source Distribution

lex_the_hacker-0.1.0.tar.gz (85.4 kB view details)

Uploaded Source

Built Distribution

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

lex_the_hacker-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file lex_the_hacker-0.1.0.tar.gz.

File metadata

  • Download URL: lex_the_hacker-0.1.0.tar.gz
  • Upload date:
  • Size: 85.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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":null}

File hashes

Hashes for lex_the_hacker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ebd02cc2510ab06fa4f45c2bcbd186f1d65460f62906b5885500062c188197a
MD5 d7b62f809b6ef8a0e2a37da16cda9f00
BLAKE2b-256 0f5400aa7cde05f297e015a481bdf2e10e75a196685e2a8dbb9f7e2d222f9bfa

See more details on using hashes here.

File details

Details for the file lex_the_hacker-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lex_the_hacker-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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":null}

File hashes

Hashes for lex_the_hacker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4619c265c9157c5ecfa35872207acb40d60117d46a0b7bee2b65fb1ac38489bf
MD5 960ec15f8a342dbd09e499fc2ec27b6d
BLAKE2b-256 eeea2fa7c47c338fb7e740ff925c94e95ffa1e8e1c5af40654577ef2c9d6b6ff

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page