diff options
| author | Paul Buetow <paul@buetow.org> | 2025-04-25 18:10:09 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-04-25 18:10:09 +0300 |
| commit | 914af52d30e2b8518590a054170159dbeedb7411 (patch) | |
| tree | d8b74a1262fad43b1b5255031e544affab42b337 | |
| parent | 12c227bf8403895a519217ff54a4bb02f3f68b08 (diff) | |
better
| -rw-r--r-- | dotfiles/nvim/init.lua | 26 | ||||
| -rwxr-xr-x | dotfiles/scripts/copilot (renamed from dotfiles/scripts/hx.nvim-prompt) | 20 |
2 files changed, 30 insertions, 16 deletions
diff --git a/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua index 4f593a2..c3b8701 100644 --- a/dotfiles/nvim/init.lua +++ b/dotfiles/nvim/init.lua @@ -48,15 +48,23 @@ vim.api.nvim_create_autocmd("BufEnter", { end, }) -vim.api.nvim_create_user_command('CopilotAskFromInputFile', function() +vim.api.nvim_create_user_command('CopilotAsk', function(args) 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) + local input + if args.args and args.args ~= "" then + input = args.args else - print("Error: Unable to open input file.") + 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 -end, { force = true, range = true }) + chat.ask(input) +end, { force = true, range = true, nargs = "?" }) + + diff --git a/dotfiles/scripts/hx.nvim-prompt b/dotfiles/scripts/copilot index de6590c..dcb2837 100755 --- a/dotfiles/scripts/hx.nvim-prompt +++ b/dotfiles/scripts/copilot @@ -1,24 +1,30 @@ #!/usr/bin/env zsh -declare -r STDIN_FILE=~/.hx-prompt-nvim-stdin +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 -cat > $STDIN_FILE &>/dev/null -declare -r PROMPT="$(hx.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 -$PROMPT for the following: +$INPUT_PROMPT for the following: -$(cat $STDIN_FILE). +$(cat $STDIN_FILE) -If the result is code, code only without \`\`\`-markers at the beginning and the end. +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 +':CopilotAskFromInputFile'; mv $OUTPUT_FILE $OUTPUT_FILE.done" +tmux split-window -v "nvim +':CopilotAsk'; mv $OUTPUT_FILE $OUTPUT_FILE.done" while [ ! -f "$OUTPUT_FILE.done" ]; do sleep 0.2 |
