summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-04-25 22:51:53 +0300
committerPaul Buetow <paul@buetow.org>2025-04-25 22:51:53 +0300
commitf2b8bedd5a0c1f0b78c91c1e793fac9d459ee808 (patch)
tree5b97cba30d7ebbfb7c6e03c64eda566e82e9cbf1
parentb21360f95646f1d6d96eff0f9c3c5b51468836f9 (diff)
parent48178ad7d5a1f61790e6fa510971e0636d97d61a (diff)
Merge branch 'master' of codeberg.org:snonux/rexfiles
-rw-r--r--dotfiles/fish/conf.d/ai.fish2
-rw-r--r--dotfiles/helix/config.toml4
-rw-r--r--dotfiles/nvim/init.lua70
-rwxr-xr-xdotfiles/scripts/ai7
-rwxr-xr-xdotfiles/scripts/hx.nvim-copilot-prompt32
5 files changed, 112 insertions, 3 deletions
diff --git a/dotfiles/fish/conf.d/ai.fish b/dotfiles/fish/conf.d/ai.fish
index 5ad80d2..4e89bbb 100644
--- a/dotfiles/fish/conf.d/ai.fish
+++ b/dotfiles/fish/conf.d/ai.fish
@@ -2,4 +2,4 @@ abbr -a gpt chatgpt
abbr -a gpti "chatgpt --interactive"
abbr -a suggest 'gh copilot suggest'
abbr -a explain 'gh copilot explain'
-abbr -a ai 'aichat -e'
+abbr -a aic 'aichat -e'
diff --git a/dotfiles/helix/config.toml b/dotfiles/helix/config.toml
index 1803944..1893b94 100644
--- a/dotfiles/helix/config.toml
+++ b/dotfiles/helix/config.toml
@@ -57,8 +57,8 @@ C-s = { e = ":set-option soft-wrap.enable true", d = ":set-option soft-wrap.enab
# Buffer stuff
C-q = ":buffer-close"
-# AI commands (requires cargo install aichat)
-C-p = { c = ":pipe aichat correct this sentence and only print out the corrected text", r = ":pipe aichat restructure and reword the input and dont leave information out and only print out the new text", a = ":pipe aichat rewrite this in a more casual style", n = ":pipe aichat these are book notes of mine. correct the grammar and re-organize the notes. use bullet points for short information and whole paragraphs for longer one. the output must be in Gemini Gemtext format with the star * as the bullet point symbol and not the minus - . dont leave out any content.", p = ":pipe hx.aichat-prompt" }
+# AI commands are good here.
+C-p = { c = ":pipe ai correct this sentence and only print out the corrected text", r = ":pipe ai restructure and reword the input and dont leave information out and only print out the new text", a = ":pipe ai rewrite this in a more casual style", n = ":pipe ai these are book notes of mine. correct the grammar and re-organize the notes. use bullet points for short information and whole paragraphs for longer one. the output must be in Gemini Gemtext format with the star * as the bullet point symbol and not the minus - . dont leave out any content.", p = ":pipe ai" }
# Git commands
C-g = { d = ":run-shell-command git diff", p = ":run-shell-command git pull", u = ":run-shell-command git push", t = ":run-shell-command tmux new-window -n hx-git-tig tig", c = ":run-shell-command tmux split-window -v 'git commit -a'" }
diff --git a/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua
new file mode 100644
index 0000000..c3b8701
--- /dev/null
+++ b/dotfiles/nvim/init.lua
@@ -0,0 +1,70 @@
+
+require("CopilotChat").setup {
+ -- See Configuration section for options
+}
+
+local timer = vim.loop.new_timer() -- Initialize the timer
+
+vim.api.nvim_create_autocmd("BufEnter", {
+ pattern = "*",
+ callback = function()
+ if vim.bo.filetype == "copilot-chat" then
+ local copilot_chat_buf = vim.api.nvim_get_current_buf()
+ vim.cmd("wincmd _") -- Maximize height
+ vim.cmd("wincmd |") -- Maximize width
+ local file_path = vim.fn.expand("~/.copilot_chat_output.txt")
+
+ -- Start the timer with a 2-second interval
+ timer:start(1000, 1000, vim.schedule_wrap(function()
+ if copilot_chat_buf and vim.api.nvim_buf_is_valid(copilot_chat_buf) then
+ -- Get all lines in the buffer
+ local lines = vim.api.nvim_buf_get_lines(copilot_chat_buf, 0, -1, false)
+
+ -- Check for the stopping condition
+ local user_line_count = 0
+ for _, line in ipairs(lines) do
+ if line:find("^## User") then
+ user_line_count = user_line_count + 1
+ if user_line_count >= 2 then
+ print("Stopping write process: Two '## User' lines detected.")
+ timer:stop()
+ -- Write the buffer content to the file
+ vim.api.nvim_buf_call(copilot_chat_buf, function()
+ vim.cmd("write! " .. file_path)
+ end)
+ vim.cmd("qa!")
+ return
+ end
+ end
+ end
+
+ -- Write the buffer content to the file
+ vim.api.nvim_buf_call(copilot_chat_buf, function()
+ vim.cmd("write! " .. file_path)
+ end)
+ end
+ end))
+ end
+ end,
+})
+
+vim.api.nvim_create_user_command('CopilotAsk', function(args)
+ local chat = require("CopilotChat")
+ local input
+ if args.args and args.args ~= "" then
+ input = args.args
+ else
+ local input_file = os.getenv("HOME") .. "/.copilot_chat_input.txt"
+ local file = io.open(input_file, "r")
+ if file then
+ input = file:read("*all")
+ file:close()
+ else
+ print("Error: Unable to open input file.")
+ return
+ end
+ end
+ chat.ask(input)
+end, { force = true, range = true, nargs = "?" })
+
+
diff --git a/dotfiles/scripts/ai b/dotfiles/scripts/ai
new file mode 100755
index 0000000..7515659
--- /dev/null
+++ b/dotfiles/scripts/ai
@@ -0,0 +1,7 @@
+#!/usr/bin/env zsh
+
+if [ $(uname) = Darwin ]; then
+ exec hx.nvim-copilot-prompt "$@"
+else
+ exec hx.aichat-prompt "$@"
+fi
diff --git a/dotfiles/scripts/hx.nvim-copilot-prompt b/dotfiles/scripts/hx.nvim-copilot-prompt
new file mode 100755
index 0000000..dcb2837
--- /dev/null
+++ b/dotfiles/scripts/hx.nvim-copilot-prompt
@@ -0,0 +1,32 @@
+#!/usr/bin/env zsh
+
+declare -r STDIN_FILE=~/.copilot_prompt_stdin.txt
+declare -r INPUT_FILE=~/.copilot_chat_input.txt
+declare -r OUTPUT_FILE=~/.copilot_chat_output.txt
+declare INPUT_PROMPT
+
+if [ -f $OUTPUT_FILE.done ]; then
+ rm $OUTPUT_FILE.done
+fi
+cat > $STDIN_FILE &>/dev/null
+
+if [ $# -eq 0 ]; then
+ INPUT_PROMPT="$(hx.prompt)"
+else
+ INPUT_PROMPT="$@"
+fi
+
+cat <<INPUT_FILE > $INPUT_FILE
+$INPUT_PROMPT for the following:
+
+$(cat $STDIN_FILE)
+
+If the result is code, print out the code only, don't print the \`\`\`-markers around the code block.
+INPUT_FILE
+
+tmux split-window -v "nvim +':CopilotAsk'; mv $OUTPUT_FILE $OUTPUT_FILE.done"
+
+while [ ! -f "$OUTPUT_FILE.done" ]; do
+ sleep 0.2
+done
+sed -n '/^## Copilot/,/^## User/ { /^## Copilot/d; /\[file:/d; /^## User/d; p; }' $OUTPUT_FILE.done