Thats right! I made another EI AI plugin for kakoune, lately I feel gpt is kinda trash tbh, so I ported my plugin to use gemini: GitHub - eko234/kakkak
Example config is:
plug "eko234/kakkak" do %{
go install
} config %{
kakkakreifywith GEMINI_API_KEY
define-command gback %{
set global kakkakstarted false
try %{
db! chatkakkak
}
kakkakreifywith GEMINI_API_KEY
}
gback
map global user i ": gpt "
}
If you have a 1 char size selection It will just take the prompt you add after the gpt command, but if you have a +1 char text selection, it will append that to the prompt you write after the gpt command.
This gave me the idea to build a simple version just using kakscript
define-command gemini -params .. -docstring "Query Gemini AI with optional prompt" %{
evaluate-commands -draft %{
# If nothing selected (single char), select from current line upwards
try %{
execute-keys '<a-k>..<ret>' # Check if selection is more than 1 char
} catch %{
execute-keys 'x<a-h>Gg' # Select from current line to beginning
}
# Save selection to register g for context
execute-keys '"gy'
}
evaluate-commands %sh{
if [ -z "$GEMINI_API_KEY" ]; then
echo "fail 'GEMINI_API_KEY not set'"
exit
fi
# Build the query from the context registry g
if [ $# -gt 0 ]; then
full_query=$(printf '%s\n\n%s' "$kak_reg_g" "$@")
else
full_query="$kak_reg_g"
fi
# Escape for JSON using jq
json_query=$(printf '%s' "$full_query" | jq -Rs .)
response=$(curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d "{\"contents\":[{\"parts\":[{\"text\":$json_query}]}]}" | \
jq -r '.candidates[0].content.parts[0].text // empty')
if [ -n "$response" ]; then
echo "execute-keys 'o<esc>'"
printf 'set-register z %s%s%s\n' '%§' "$response" '§'
echo "execute-keys '\"zP'"
else
echo "fail 'No response from Gemini'"
fi
}
}
Of course, you can change that curl command to whichever provider you prefer, and it should work, too. What do you think?
I am hoping @alexherbo2 will look at it and simplify it.