From 1d5e5e7c18fbe3b94d49b8593a00bfdc4ba164e7 Mon Sep 17 00:00:00 2001 From: Joel Drotleff Date: Tue, 19 Dec 2023 21:14:44 -0800 Subject: [PATCH 1/2] Allow loading custom prompts from local file fix more fix --- lua/chatgpt/prompts.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/chatgpt/prompts.lua b/lua/chatgpt/prompts.lua index 5e280e8d..d4a7aa29 100644 --- a/lua/chatgpt/prompts.lua +++ b/lua/chatgpt/prompts.lua @@ -82,10 +82,19 @@ local finder = function(opts) end if not job_started then + + local load_file_command = "" + if string.match(opts.url, "^/") ~= nil then + load_file_command = "cat" + else + load_file_command = "curl" + end + job_started = true + job :new({ - command = "curl", + command = load_file_command, args = { opts.url, }, From f15c7282f4affb62aab0b62950402114bd9b0037 Mon Sep 17 00:00:00 2001 From: Joel Drotleff Date: Wed, 20 Dec 2023 20:29:36 -0800 Subject: [PATCH 2/2] =?UTF-8?q?expand=20file=20url=20to=20support=20i.e.?= =?UTF-8?q?=20=E2=80=98$HOME=E2=80=99,=20=E2=80=98~=E2=80=99=20in=20local?= =?UTF-8?q?=20file=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/chatgpt/prompts.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/chatgpt/prompts.lua b/lua/chatgpt/prompts.lua index d4a7aa29..5875c61c 100644 --- a/lua/chatgpt/prompts.lua +++ b/lua/chatgpt/prompts.lua @@ -84,10 +84,15 @@ local finder = function(opts) if not job_started then local load_file_command = "" - if string.match(opts.url, "^/") ~= nil then + local expanded_url = vim.fn.expand(opts.url) + local file_or_web_url = "" + local starts_with_slash = string.match(expanded_url, "^/") ~= nil + if starts_with_slash then load_file_command = "cat" + file_or_web_url = expanded_url else load_file_command = "curl" + file_or_web_url = opts.url end job_started = true @@ -96,7 +101,7 @@ local finder = function(opts) :new({ command = load_file_command, args = { - opts.url, + file_or_web_url, }, on_exit = vim.schedule_wrap(function(j, exit_code) if exit_code ~= 0 then