Skip to content

Commit 0f3b5bd

Browse files
zibohRobitx
andauthored
fix: symbolic links on Windows without admin rights (#177)
* Create Symbolic link for Windows * chore: keeping // gsub to win only --------- Co-authored-by: Tibor Schmidt <[email protected]>
1 parent df7eb5b commit 0f3b5bd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lua/gp/init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ end
406406
M.not_chat = function(buf, file_name)
407407
file_name = vim.fn.resolve(file_name)
408408
local chat_dir = vim.fn.resolve(M.config.chat_dir)
409+
if vim.fn.has("win32") then
410+
file_name = file_name:gsub("\\", "/")
411+
chat_dir = chat_dir:gsub("\\", "/")
412+
end
409413
if not M.helpers.starts_with(file_name, chat_dir) then
410414
return "resolved file (" .. file_name .. ") not in chat dir (" .. chat_dir .. ")"
411415
end
@@ -524,7 +528,9 @@ M.prep_chat = function(buf, file_name)
524528

525529
-- make last.md a symlink to the last opened chat file
526530
local last = M.config.chat_dir .. "/last.md"
527-
if file_name ~= last then
531+
if file_name ~= last and vim.fn.has("win32") then
532+
os.execute("pwsh -Noprofile -c New-Item -Force -ItemType SymbolicLink -Path " .. last .. " -Target " .. file_name)
533+
elseif file_name ~= last then
528534
os.execute("ln -sf " .. file_name .. " " .. last)
529535
end
530536
end

0 commit comments

Comments
 (0)