summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-04-25 14:26:29 +0300
committerPaul Buetow <paul@buetow.org>2025-04-25 14:26:29 +0300
commit9d49c21dc973e4cb88d716b83b6b50db1e574649 (patch)
tree56e92bd398bba987873ae8cd5198d4bd9732895c
parenta98486eb80e15005bd4f57d4de62523c47683bcc (diff)
workaround
-rw-r--r--dotfiles/nvim/init.lua44
-rwxr-xr-xdotfiles/scripts/hx.nvim-prompt17
2 files changed, 61 insertions, 0 deletions
diff --git a/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua
new file mode 100644
index 0000000..ae4ab5d
--- /dev/null
+++ b/dotfiles/nvim/init.lua
@@ -0,0 +1,44 @@
+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
+ for _, line in ipairs(lines) do
+ if line:find("^COPILOT_END") then
+ print("Stopping write process: 'COPILOT_END' 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
+
+ -- 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,
+})
diff --git a/dotfiles/scripts/hx.nvim-prompt b/dotfiles/scripts/hx.nvim-prompt
new file mode 100755
index 0000000..05ad1a3
--- /dev/null
+++ b/dotfiles/scripts/hx.nvim-prompt
@@ -0,0 +1,17 @@
+#!/usr/bin/env zsh
+
+declare -r STDIN_FILE=~/.hx-prompt-nvim-stdin
+cat > $STDIN_FILE &>/dev/null
+declare -r PROMPT="$(hx.prompt)"
+
+declare -r REPLY_FILE=~/.copilot_chat_output.txt
+if [ -f $REPLY_FILE.done ]; then
+ rm $REPLY_FILE.done
+fi
+
+tmux split-window -v "nvim +':CopilotChat $PROMPT for the following: $(cat $STDIN_FILE). If the result is code, code only without code-block at the beginning and the end. End the output with COPILOT_END.'; mv $REPLY_FILE $REPLY_FILE.done"
+
+while [ ! -f "$REPLY_FILE.done" ]; do
+ sleep 0.2
+done
+sed -n '/## Copilot/,/^COPILOT_END/ { /^## Copilot/d; /\[file:/d; /^COPILOT_END/d; p; }' $REPLY_FILE.done