The plugin implements a custom completion widget that handles:
# File and directory completion with @: Review this file @<TAB># Opens fzf with file preview# Agent completion with ::<TAB># Shows list of available agents# Filtered completion:sage<TAB># Pre-filters to agents matching "sage"
function forge-completion() { local current_word="${LBUFFER##* }" # Handle @ completion (files and directories) if [[ "$current_word" =~ ^@.*$ ]]; then local filter_text="${current_word#@}" local selected local fzf_args=( --preview="if [ -d {} ]; then ls -la --color=always {}; else bat --color=always --style=numbers {}; fi" ) local file_list=$(fd --type f --type d --hidden --exclude .git) selected=$(echo "$file_list" | fzf --query "$filter_text" "${fzf_args[@]}") if [[ -n "$selected" ]]; then selected="@[${selected}]" LBUFFER="${LBUFFER%$current_word}" BUFFER="${LBUFFER}${selected}${RBUFFER}" fi fi # Handle :command completion if [[ "${LBUFFER}" =~ "^:([a-zA-Z][a-zA-Z0-9_-]*)?$" ]]; then local filter_text="${LBUFFER#:}" local commands_list=$(forge commands list) local selected=$(echo "$commands_list" | fzf --query "$filter_text") if [[ -n "$selected" ]]; then local command_name="${selected%% *}" BUFFER=":$command_name " fi fi}
# Case-insensitive completionzstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'# Use menu selectionzstyle ':completion:*' menu select# Group results by categoryzstyle ':completion:*' group-name ''# Show descriptions for optionszstyle ':completion:*' verbose yes# Color completion menuzstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# Use fd instead of find (faster)export _FORGE_FD_CMD="fd"# Use bat for file previewsexport _FORGE_CAT_CMD="bat --color=always --style=numbers"# Customize preview windowexport _FORGE_PREVIEW_WINDOW="--preview-window=bottom:75%:wrap"
# Type prefix before TAB for filtered results$ forge agent li<TAB>list # Only shows commands starting with "li"$ :plan<TAB>planner # Only shows agents starting with "plan"