if [[ ! "$ZSH_VERSION" ]]; then
echo "Error: This script must be run by ZSH."
return 1
fi
termsearch-search() {
local temp_file=$(mktemp -t termsearch.XXXXXX)
termsearch search -o "$temp_file" "$LBUFFER"
local commandline
while IFS=$'\t' read -r key val; do
case "$key" in
commandline) commandline="$val" ;;
esac
done < "$temp_file"
command rm -f "$temp_file"
if [[ -n "$commandline" ]]; then
LBUFFER="$commandline"
CURSOR=$#LBUFFER
zle redisplay
fi
}
zle -N termsearch-search
bindkey '^R' termsearch-search