1
0
Fork 0
codesnap.nvim/lua/codesnap/utils/path.lua

30 lines
651 B
Lua
Raw Normal View History

local string_utils = require("codesnap.utils.string")
2024-02-19 14:27:17 +00:00
local path_utils = {}
function path_utils.get_escaped_cwd()
local cwd = vim.fn.getcwd()
return string_utils.escape(cwd)
end
2024-02-19 14:27:17 +00:00
function path_utils.back(path)
local parsed_path, _ = path:gsub("/[^\\/]+/?$", "")
return parsed_path
end
function path_utils.get_workspace()
local cwd = vim.fn.getcwd()
local _, _, workspace = string.find(cwd, "/([^/]+)$")
return workspace == nil and "" or workspace
end
function path_utils.get_relative_path()
local full_file_path = vim.fn.expand("%:p")
return full_file_path:gsub(path_utils.get_escaped_cwd(), ""):sub(2)
end
2024-02-19 14:27:17 +00:00
return path_utils