Skip to content

Commit f15c728

Browse files
committed
expand file url to support i.e. ‘$HOME’, ‘~’ in local file urls
1 parent 1d5e5e7 commit f15c728

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lua/chatgpt/prompts.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,15 @@ local finder = function(opts)
8484
if not job_started then
8585

8686
local load_file_command = ""
87-
if string.match(opts.url, "^/") ~= nil then
87+
local expanded_url = vim.fn.expand(opts.url)
88+
local file_or_web_url = ""
89+
local starts_with_slash = string.match(expanded_url, "^/") ~= nil
90+
if starts_with_slash then
8891
load_file_command = "cat"
92+
file_or_web_url = expanded_url
8993
else
9094
load_file_command = "curl"
95+
file_or_web_url = opts.url
9196
end
9297

9398
job_started = true
@@ -96,7 +101,7 @@ local finder = function(opts)
96101
:new({
97102
command = load_file_command,
98103
args = {
99-
opts.url,
104+
file_or_web_url,
100105
},
101106
on_exit = vim.schedule_wrap(function(j, exit_code)
102107
if exit_code ~= 0 then

0 commit comments

Comments
 (0)