Skip to content

Instantly share code, notes, and snippets.

@fabiomontefuscolo
Last active January 27, 2026 19:48
Show Gist options
  • Select an option

  • Save fabiomontefuscolo/3ffe82d80a0b784bbe16bd04de5f8fc3 to your computer and use it in GitHub Desktop.

Select an option

Save fabiomontefuscolo/3ffe82d80a0b784bbe16bd04de5f8fc3 to your computer and use it in GitHub Desktop.
fabric-ai-zsh-widget.zsh
fabric-command-helper() {
# Tell ZLE we're about to do terminal I/O
zle -I
# Print prompt explicitly to terminal
print -n "Ask about command: "
# Read input from terminal
local question
read question < /dev/tty
# If user provided no input, return
if [[ -z "$question" ]]; then
zle reset-prompt
return
fi
# Show a loading message
print "⏳ Asking fabric-ai..."
# Call fabric-ai with the question
local result
result=$(echo "$question" | fabric-ai --pattern create_command 2>/dev/null)
# Clean up any markdown code fences and extra whitespace
result=$(echo "$result" | sed 's/^```[a-z]*$//' | sed '/^```$/d' | sed '/^$/d' | tr -d '\n' | xargs)
# If we got a result, put it in the buffer
if [[ -n "$result" ]]; then
BUFFER="$result"
CURSOR=$#BUFFER # Move cursor to end of line
else
BUFFER="# Error: No response from fabric-ai"
fi
# Reset the prompt and redisplay
zle reset-prompt
}
# Register the widget with ZLE
zle -N fabric-command-helper
# Bind it to Ctrl+X, Ctrl+F (for "fabric")
bindkey '^X^F' fabric-command-helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment