Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Created March 14, 2025 22:35
Show Gist options
  • Save Profpatsch/af85283b7a1961fc2d56362a6efa033d to your computer and use it in GitHub Desktop.
Save Profpatsch/af85283b7a1961fc2d56362a6efa033d to your computer and use it in GitHub Desktop.
pass everything after :: to an LLM and replace the output in the fish shell command line
function llm_replace_commandline
set -l cmdline (commandline)
# Extract everything after '::' (last captured group), and use the name as template
set -l extracted (string match --groups-only -r '.*::(\S+)?\W?(.*)$' -- $cmdline)
# If no match, do nothing
if test -z "$extracted"
notify-send "no :: match"
return
end
# Remove "::command args" from the input line
commandline --replace (string split --fields 1 --right --max 1 "::" -- $cmdline)
set -l cmd
if test (count $extracted) -gt 1
set cmd llm -t "$extracted[1]" "$extracted[2]"
else
set cmd llm -s "print a single-line plain shell command, don’t put it in a markdown block" "$extracted[1]"
end
notify-send "running command:" (string escape "$cmd")
# Execute extracted command and stream output
$cmd | while read --line line
commandline -i "$line"
end
end
# Bind to Ctrl-G
bind \cg llm_replace_commandline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment