nlp2terminal
v0.1.0
Published
Describe what you want in plain English, hit your hotkey, get a ready-to-run terminal command on your command line.
Readme
nlp2terminal
Press a hotkey in any terminal, type what you want in plain English, and the generated shell command lands directly on your command line — no copy/paste, just press Enter to run it (or edit/cancel it first, since it's a normal editable line).
How it works
nlp2terminal is one small binary with a prompt subcommand that:
- reads your one-line request from the real terminal,
- calls an OpenAI-compatible chat completions endpoint,
- prints only the generated command to stdout (all UI goes to stderr).
A tiny per-shell snippet (installed via nlp2terminal init <shell>) binds a
key to a widget/function that runs nlp2terminal prompt, captures its
stdout, and replaces the current input line with it — using each shell's own
line-editing hook (zsh ZLE, bash bind -x, fish bind, PowerShell's
PSReadLine). That's what makes "press Enter and it just runs" possible: the
terminal never sees "output," it sees you typing a command.
Install
npm install -g nlp2terminal(Or from source: npm install && npm run build && npm link.)
Configure the AI provider
If you already export an API key for a common provider — which most people do, for other CLIs/SDKs — nlp2terminal picks it up automatically, with a sensible default base URL and model, and you don't need to configure anything:
| Env var already in your shell | Provider |
|---|---|
| OPENAI_API_KEY | OpenAI |
| ANTHROPIC_API_KEY | Anthropic |
| GROQ_API_KEY | Groq |
| GEMINI_API_KEY / GOOGLE_API_KEY | Google Gemini |
| MISTRAL_API_KEY | Mistral |
| DEEPSEEK_API_KEY | DeepSeek |
| TOGETHER_API_KEY | Together AI |
| OPENROUTER_API_KEY | OpenRouter |
| XAI_API_KEY | xAI (Grok) |
| FIREWORKS_API_KEY | Fireworks AI |
| PERPLEXITY_API_KEY | Perplexity |
| OLLAMA_HOST | local Ollama (no key needed) |
For anything else — a self-hosted vLLM server, a specific model/base URL
override, or a provider not in the table above — set these three, either as
real environment variables or in ~/.config/nlp2terminal/.env (see
.env.example):
AI_PROVIDER_BASE_URL=https://api.openai.com/v1
AI_PROVIDER_MODEL=gpt-4o-mini
AI_PROVIDER_API_KEY=sk-...AI_PROVIDER_* always wins per-field when set, so you can mix and match —
e.g. keep using your existing OPENAI_API_KEY for auth but set just
AI_PROVIDER_MODEL=gpt-4.1 to override the model.
Any OpenAI-compatible /chat/completions endpoint works.
Using a "thinking"/reasoning model? It writes out its reasoning before
the answer — sometimes 1000+ tokens' worth — and if it gets cut off
mid-thought you'll see an explanation instead of a command. Raise the
response budget with AI_PROVIDER_MAX_TOKENS (default 4096):
AI_PROVIDER_MAX_TOKENS=8192Verify it's wired up correctly — this also prints which provider/env vars were detected:
nlp2terminal doctorEnable the hotkey
Add one line to your shell's profile, then restart your shell (or source it).
| Shell | Add to | Line |
|---|---|---|
| zsh | ~/.zshrc | eval "$(nlp2terminal init zsh)" |
| bash | ~/.bashrc | eval "$(nlp2terminal init bash)" |
| fish | ~/.config/fish/config.fish | nlp2terminal init fish \| source |
| PowerShell | $PROFILE | Invoke-Expression (nlp2terminal init powershell \| Out-String) |
This installs two entry points in your shell:
- Alt+K (Option+K on macOS) — live hotkey, edits your current line in place.
l2t <request>— type it as a normal command instead of using the hotkey, e.g.l2t list files over 5mb.
By default this binds Alt+K, not Ctrl+K — Ctrl+K is already kill-line
in most shells/terminals and reliably collides with other tools, whereas
Alt+K is conventionally unbound. Alt-combos are sent as the byte sequence ESC
followed by the letter (\x1bk), which is how terminals represent "Meta"
keys at the protocol level — not a Kitty-keyboard-protocol sequence, so it
works on old and new terminals alike, on Linux and in Windows
Terminal/PowerShell, with no configuration needed there.
Getting Alt+K (Option+K) working on macOS
macOS terminal apps generally treat Option+key as a way to type accented or special characters (e.g. Option+K types "˚" on a US layout) rather than sending ESC+k, unless the terminal is told otherwise. Pick your terminal:
iTerm2 — Preferences → Keys → Key Mappings → + → record Option+K →
Action: "Send Hex Code" → value 0x1b 0x6b. (Scoped to just this one key
combo, so other Option-based accented characters keep working.)
Terminal.app — Preferences → Profiles → Keyboard tab → check "Use Option as Meta Key". This is a blanket toggle (affects all Option combos, not just K), since Terminal.app has no per-key remapping.
Warp — Settings → Keyboard Shortcuts → add a custom binding for
Option+K sending the escape sequence \x1bk.
kitty (~/.config/kitty/kitty.conf):
map opt+k send_text all \x1bkAlacritty (~/.config/alacritty/alacritty.toml) — either set Option to
act as Alt globally:
option_as_alt = "Both"or scope it to just this key:
[[keyboard.bindings]]
key = "K"
mods = "Alt"
chars = "k"WezTerm (~/.wezterm.lua):
config.send_composed_key_when_left_alt_is_pressed = false
config.keys = {
{ key = "k", mods = "ALT", action = wezterm.action.SendString("\x1bk") },
}Usage
Live hotkey
Press Alt+K. A ✦ prompt appears right on your current line:
✦ find all png files over 5mb in this folder and list them by sizePress Enter once to generate — a moment later the line is replaced with:
find . -iname '*.png' -size +5M -exec du -h {} + | sort -rhPress Enter again to run it, or edit it first, or Ctrl+C to cancel.
l2t as a normal command
$ l2t find all png files over 5mb in this folder and list them by size- zsh: the generated command is staged directly into your next prompt's
edit buffer (zsh's native
print -z) — just press Enter. - bash / fish / PowerShell: there's no equivalent built-in to pre-fill the
next prompt in these shells (and the lower-level trick some tools use to
simulate keystrokes,
TIOCSTI, is disabled by default on most current Linux kernels for security). The command is staged into your shell history instead — press Up-Arrow, then Enter to run it.
License
Eligapris License (a modified MIT License) — free for personal and non-commercial use with attribution; redistribution, resale, and commercial use require permission from Eligapris. See LICENSE for the full terms.
