I've been looking into using local ai agents to replace warp-terminal
so far i've come up fish shell redirecting to gptme or opencode when it sees a command not found..
Why:
• Sometimes I instinctively type a question into the terminal (e.g. “what is the disk usage on this pc”) and fish/basically every shell just errors.
• I wanted that to become useful: if it’s not a real command, send it to gptme automatically.
How (fish 4.x):
• Implemented a custom fish_command_not_found handler (~/.config/fish/functions/fish_command_not_found.fish).
◦ If the unknown input is multi-word, treat it like a question and run: gptme -y "<question>"
◦ If it’s a single word (likely a typo like sl), keep normal behavior (don’t spam the LLM).
• Added explicit “slash commands”:
◦ /ai "question" → routes to gptme
◦ /code "question" → routes to opencode
• Made /ai and /code work two ways:
1) via fish abbreviations (so typing /ai ... expands cleanly)
2) even if abbreviations don’t expand, the command-not-found handler special-cases /ai and /code and routes them anyway
Commands/functions added:
• ~/.config/fish/functions/ai.fish → gptme -y ...
• ~/.config/fish/functions/code.fish → opencode run -- "<message>" (important: plain opencode <words> treats the first arg as a project dir)
• ~/.config/fish/conf.d/ai-routing.fish → defines abbreviations + a quick toggle
Outcome:
• Typing: what is the disk usage on this pc now automatically runs gptme and answers, instead of failing.
• /ai ... reliably routes to gptme
• /code ... reliably routes to opencode run (after fixing the “project path” gotcha)
Safety / reversibility:
• Built-in quick toggle:
◦ ai-router-disable (turn it off)
◦ ai-router-enable (turn it back on)
• It only triggers in interactive shells and only auto-routes multi-word unknown commands.
Open to any other suggestions on how to get that natural language in FIsh, this is a good start, I've got gptme and opencode routing via openrouter.. gptme is very close to what i need.
https://gptme.org/
#daveknowstech #linux #homelab