Skip to content

Instantly share code, notes, and snippets.

@ffesseler
Last active January 25, 2026 10:58
Show Gist options
  • Select an option

  • Save ffesseler/653d26313ad4ea07dbe3320ff1954103 to your computer and use it in GitHub Desktop.

Select an option

Save ffesseler/653d26313ad4ea07dbe3320ff1954103 to your computer and use it in GitHub Desktop.
Shortcut to convert a natural-language request into the corresponding command line
# ZLE widget for cli - press Ctrl+X to convert human prompt to command inline
# Paste this into your ~/.zshrc
# Requires zsh & llm (https://github.com/simonw/llm) installed
# Adapt prompt, LLM, shortcut model to your needs
CLI_MODEL="gemini/gemini-2.5-flash-lite"
CLI_PROMPT="Output the bash-compatible command line only that works on macOS. No markdown, no code blocks, no explanations. Just the raw command. I should be able to copy paste the result and it should work directly in bash on macOS"
CLI_SHORTCUT='^X' # Ctrl+X
_cli_widget() {
local prompt="$BUFFER"
if [[ -z "$prompt" ]]; then
return
fi
# Show processing message
BUFFER="⏳ Generating command..."
zle redisplay
# Generate command
local result=$(llm -m "$CLI_MODEL" "$prompt. $CLI_PROMPT" | \
sed 's/^```bash//; s/^```//; s/```$//' | \
tr -s '[:space:]' ' ' | \
sed 's/^ //; s/ $//')
# Replace buffer with result
if [[ -n "$result" ]]; then
BUFFER="$result"
echo "$result" | pbcopy
else
BUFFER=""
fi
zle end-of-line
}
zle -N _cli_widget
bindkey "$CLI_SHORTCUT" _cli_widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment