summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dotfiles/nvim/init.lua13
-rwxr-xr-xdotfiles/scripts/hx.nvim-prompt23
2 files changed, 29 insertions, 7 deletions
diff --git a/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua
index 4a437e8..4f593a2 100644
--- a/dotfiles/nvim/init.lua
+++ b/dotfiles/nvim/init.lua
@@ -47,3 +47,16 @@ vim.api.nvim_create_autocmd("BufEnter", {
end
end,
})
+
+vim.api.nvim_create_user_command('CopilotAskFromInputFile', function()
+ local chat = require("CopilotChat")
+ local input_file = os.getenv("HOME") .. "/.copilot_chat_input.txt"
+ local file = io.open(input_file, "r")
+ if file then
+ local input = file:read("*all")
+ file:close()
+ chat.ask(input)
+ else
+ print("Error: Unable to open input file.")
+ end
+end, { force = true, range = true })
diff --git a/dotfiles/scripts/hx.nvim-prompt b/dotfiles/scripts/hx.nvim-prompt
index 09230ae..de6590c 100755
--- a/dotfiles/scripts/hx.nvim-prompt
+++ b/dotfiles/scripts/hx.nvim-prompt
@@ -1,17 +1,26 @@
#!/usr/bin/env zsh
declare -r STDIN_FILE=~/.hx-prompt-nvim-stdin
+declare -r INPUT_FILE=~/.copilot_chat_input.txt
+declare -r OUTPUT_FILE=~/.copilot_chat_output.txt
+
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
+if [ -f $OUTPUT_FILE.done ]; then
+ rm $OUTPUT_FILE.done
fi
-tmux split-window -v "nvim +':CopilotChat $PROMPT for the following: $(cat $STDIN_FILE). If the result is code, code only without \`\`\`-markers at the beginning and the end.'; mv $REPLY_FILE $REPLY_FILE.done"
+cat <<INPUT_FILE > $INPUT_FILE
+$PROMPT for the following:
+
+$(cat $STDIN_FILE).
+
+If the result is code, code only without \`\`\`-markers at the beginning and the end.
+INPUT_FILE
+
+tmux split-window -v "nvim +':CopilotAskFromInputFile'; mv $OUTPUT_FILE $OUTPUT_FILE.done"
-while [ ! -f "$REPLY_FILE.done" ]; do
+while [ ! -f "$OUTPUT_FILE.done" ]; do
sleep 0.2
done
-sed -n '/^## Copilot/,/^## User/ { /^## Copilot/d; /\[file:/d; /^## User/d; p; }' $REPLY_FILE.done
+sed -n '/^## Copilot/,/^## User/ { /^## Copilot/d; /\[file:/d; /^## User/d; p; }' $OUTPUT_FILE.done