Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the bug related to symbolic links in Windows. #184

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lua/gp/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ end
---@param str string # string to check
---@param start string # string to check for
_H.starts_with = function(str, start)
if vim.fn.has("win32") then
str = str:gsub("\\", "/")
start = start:gsub("\\", "/")
end
return str:sub(1, #start) == start
end

Expand Down
6 changes: 1 addition & 5 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,6 @@ end
M.not_chat = function(buf, file_name)
file_name = vim.fn.resolve(file_name)
local chat_dir = vim.fn.resolve(M.config.chat_dir)
if vim.fn.has("win32") == 1 then
file_name = file_name:gsub("\\", "/")
chat_dir = chat_dir:gsub("\\", "/")
end
if not M.helpers.starts_with(file_name, chat_dir) then
return "resolved file (" .. file_name .. ") not in chat dir (" .. chat_dir .. ")"
end
Expand Down Expand Up @@ -812,7 +808,7 @@ M.cmd.ChatToggle = function(params, system_prompt, agent)
if params.range ~= 2 then
-- check if last.md chat file exists and open it
local last = M.config.chat_dir .. "/last.md"
if vim.fn.filereadable(last) == 1 then
if vim.fn.filereadable(last) == 1 and last ~= vim.fn.resolve(last) then
-- resolve symlink
last = vim.fn.resolve(last)
M.open_buf(last, M.resolve_buf_target(params), M._toggle_kind.chat, true)
Expand Down
2 changes: 1 addition & 1 deletion lua/gp/tasker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ M.grep_directory = function(buf, directory, pattern, callback)
-- strip leading and trailing non alphanumeric characters
local re = pattern:gsub("^%W*(.-)%W*$", "%1")

M.run(buf, "grep", { "-irEn", "--null", pattern, directory }, function(c, _, stdout, _)
M.run(buf, "grep", { "-irEn", "--null", "--exclude=last.md", pattern, directory }, function(c, _, stdout, _)
local results = {}
if c ~= 0 then
callback(results, re)
Expand Down
Loading