File size: 1,467 Bytes
c981f27 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #!/usr/bin/env zsh
# Custom completion widget that handles both :commands and @ completion
function forge-completion() {
local current_word="${LBUFFER##* }"
# Handle @ completion (files and directories)
if [[ "$current_word" =~ ^@.*$ ]]; then
local filter_text="${current_word#@}"
local selected
# Use Rust's built-in file picker
selected=$(_forge_select_with_query "$filter_text" file)
if [[ -n "$selected" ]]; then
selected="@[${selected}]"
LBUFFER="${LBUFFER%$current_word}"
BUFFER="${LBUFFER}${selected}${RBUFFER}"
CURSOR=$((${#LBUFFER} + ${#selected}))
fi
zle reset-prompt
return 0
fi
# Handle :command completion (supports letters, numbers, hyphens, underscores)
if [[ "${LBUFFER}" =~ "^:([a-zA-Z][a-zA-Z0-9_-]*)?$" ]]; then
# Extract the text after the colon for filtering
local filter_text="${LBUFFER#:}"
# Use Rust's built-in command picker
local selected
selected=$(_forge_select_with_query "$filter_text" command)
if [[ -n "$selected" ]]; then
# Replace the current buffer with the selected command
BUFFER=":$selected "
CURSOR=${#BUFFER}
fi
zle reset-prompt
return 0
fi
# Fall back to default completion
zle expand-or-complete
}
|