2 Commits

5 changed files with 129 additions and 2 deletions

View File

@@ -11,7 +11,6 @@ window-save-state = always
# Also makes some of the below macos-titlebar-* things not matter, but
# will take affect if this is set to true.
window-decoration = false
winow-save-state = true
copy-on-select = true
quit-after-last-window-closed = true

View File

@@ -48,6 +48,17 @@ require("lazy").setup({
rocks = { "magick" },
},
},
{
"folke/lazydev.nvim",
ft = "lua", -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
},
{
"MeanderingProgrammer/render-markdown.nvim",
-- dependencies = { "nvim-treesitter/nvim-treesitter", "echasnovski/mini.nvim" }, -- if you use the mini.nvim suite

View File

@@ -4,6 +4,7 @@ return {
event = "VeryLazy",
dependencies = {
"MeanderingProgrammer/render-markdown.nvim",
"folke/lazydev.nvim",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer", -- source for text in buffer
"hrsh7th/cmp-path", -- source for file system paths
@@ -75,6 +76,7 @@ return {
}),
-- sources for autocompletion
sources = cmp.config.sources({
{ name = "lazydev", group_index = 0 },
{ name = "nvim_lsp" },
{ name = "luasnip" }, -- snippets
{ name = "render-markdown" }, -- markdown

View File

@@ -1,5 +1,5 @@
return {
"ghostty",
dir = "/Applications/Ghostty.app/Contents/Resources/vim/vimfiles/",
dir = vim.env.GHOSTTY_PATH .. "/Contents/Resources/vim/vimfiles/",
lazy = false,
}

115
scripts/scripts/ask-gpt Executable file
View File

@@ -0,0 +1,115 @@
#!/bin/zsh
#
# Ask chat-gpt a question and view the output.
local api_key="${OPENAI_API_KEY}"
local debug="${DEBUG}"
function usage() {
cat << EOF
Ask chat-gpt a question and view the output.
Example usage:
ask-gpt 'Who are you?'
# Send output to a file:
ask-gpt --print 'Who are you' > /tmp/gpt.md
Usage: ask-gpt [-k <key>] [-m <model>] [-p] [-j] [-h] question
Options:
-k | --key : Use api key (default: environment variable 'OPENAI_API_KEY')
-m | --model: Specify the chat-gpt model (default is 'gpt-4o-mini')
-j | --json: Print the full json output to stdout.
-p | --print: Print the output to stdout in markdown format.
-h | --help: Show usage.
Include debug output:
DEBUG=1 ask-gpt 'Who are you?'
EOF
}
######################### Helpers #########################
function debug_print {
if [ ! -z "$debug" ]; then
echo "$1"
fi
}
function makeGptInput {
echo $(jq --null-input \
--arg model "$1" \
--arg question "$2" \
'{ "model": $model, "messages": [{"role": "system", "content": "You are such a helpful assistant!" }, {"role": "user", "content": $question}] }')
}
function getGptOutput {
echo "$1" | jq '.["choices"][0]["message"]["content"]'
}
function askGpt {
local key=$1
local input=$2
echo $(curl "https://api.openai.com/v1/chat/completions" \
-sS \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $key" \
-d "$input")
}
######################### MAIN #########################
zparseopts -D -E -F -- \
{h,-help}=help \
{k,-key}:=key \
{m,-model}=model \
{j,-json}=json \
{p,-print}=printOutput
# Check if help was specified and show usage.
[ ! -z "$help" ] && usage && exit 0
local question="$1"
# Ensure there is a question / first argument.
[ -z "$question" ] && print "No question found." && usage && exit 1
# parse the api key.
if [ ! -z "$key" ]; then
api_key="${key[-1]}"
debug_print "Using custom passed in key."
fi
# Fail if we did not find an api key.
[ -z "$api_key" ] && echo "No api key found." && usage && exit 1
# Set default model if not specified.
if [ -z "$model" ]; then
model="gpt-4o-mini"
fi
debug_print "Model: $model"
# Generate the input for chat-gpt.
local input="$(makeGptInput $model $question)"
debug_print "Input: $input"
# Get the chat-gpt output.
local output="$(askGpt $api_key $input)"
debug_print "Full ouptput: $(echo $output | jq '.[]')"
# If json option is specified, then send full output to stdout and exit.
[ ! -z "$json" ] && echo "$output" | jq '.[]' && exit 0
# parse the output message.
local parsedOutput="$(getGptOutput $output)"
# Show the output based on options passed in.
if [ -z "$printOutput" ]; then
echo "# $question\n$parsedOutput" | gum format | gum pager
else
echo "# $question\n$parsedOutput" | gum format
fi