fix: path shortening does proper subpath detection

This commit is contained in:
Steven Arcangeli 2023-10-16 08:19:29 -07:00
parent 164135793d
commit 054247b9c1

View file

@ -116,14 +116,14 @@ local home_dir = assert(uv.os_homedir())
---@return string ---@return string
M.shorten_path = function(path) M.shorten_path = function(path)
local cwd = vim.fn.getcwd() local cwd = vim.fn.getcwd()
if vim.startswith(path, cwd) then if M.is_subpath(cwd, path) then
local relative = path:sub(cwd:len() + 2) local relative = path:sub(cwd:len() + 2)
if relative == "" then if relative == "" then
relative = "." relative = "."
end end
return relative return relative
end end
if vim.startswith(path, home_dir) then if M.is_subpath(home_dir, path) then
return "~" .. path:sub(home_dir:len() + 1) return "~" .. path:sub(home_dir:len() + 1)
end end
return path return path