diff options
| author | Paul Buetow <paul@buetow.org> | 2025-04-25 17:46:14 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-04-25 17:46:14 +0300 |
| commit | 12c227bf8403895a519217ff54a4bb02f3f68b08 (patch) | |
| tree | 4de90cf53d368d539df472393b2f29344ddedc91 | |
| parent | bde6ebc424a5953ea777fdae1aedbfaa940866aa (diff) | |
better
| -rw-r--r-- | dotfiles/nvim/init.lua | 13 | ||||
| -rwxr-xr-x | dotfiles/scripts/hx.nvim-prompt | 23 |
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 |
