diff --git a/lua/codesnap/config.lua b/lua/codesnap/config.lua index d2ba1b8..a91121b 100644 --- a/lua/codesnap/config.lua +++ b/lua/codesnap/config.lua @@ -25,6 +25,12 @@ local function parse_save_path(save_path) return parsed_save_path .. auto_generate_snap_filename() end +local function get_file_path(show_workspace) + local relative_path = path_utils.get_relative_path() + + return show_workspace and path_utils.get_workspace() .. "/" .. relative_path or relative_path +end + function config_module.get_config(extension) local code = visual_utils.get_selected_text() local start_line_number = visual_utils.get_start_line_number() @@ -41,7 +47,7 @@ function config_module.get_config(extension) fonts_folder = assets_folder .. "/fonts", themes_folder = assets_folder .. "/themes", theme = "base16-onedark", - file_path = static.config.has_breadcrumbs and path_utils.get_relative_path() or "", + file_path = static.config.has_breadcrumbs and get_file_path(static.config.show_workspace) or "", start_line_number = static.config.has_line_number and start_line_number or nil, }, static.config) diff --git a/lua/codesnap/static.lua b/lua/codesnap/static.lua index 670134a..4ae9869 100644 --- a/lua/codesnap/static.lua +++ b/lua/codesnap/static.lua @@ -11,6 +11,7 @@ return { breadcrumbs_separator = "/", has_breadcrumbs = false, has_line_number = false, + show_workspace = false, min_width = 0, }, cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))), diff --git a/lua/codesnap/utils/path.lua b/lua/codesnap/utils/path.lua index ebf4a54..6318c3e 100644 --- a/lua/codesnap/utils/path.lua +++ b/lua/codesnap/utils/path.lua @@ -1,17 +1,29 @@ local string_utils = require("codesnap.utils.string") local path_utils = {} +function path_utils.get_escaped_cwd() + local cwd = vim.fn.getcwd() + + return string_utils.escape(cwd) +end + 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") - local cwd = vim.fn.getcwd() - return full_file_path:gsub(string_utils.escape(cwd), ""):sub(2) + return full_file_path:gsub(path_utils.get_escaped_cwd(), ""):sub(2) end return path_utils