forked from mirror/codesnap.nvim
[Feat] add show_workspace config for display workspace in breadcrumbs
parent
a2d59ef624
commit
daf3dc6ee3
|
@ -25,6 +25,12 @@ local function parse_save_path(save_path)
|
||||||
return parsed_save_path .. auto_generate_snap_filename()
|
return parsed_save_path .. auto_generate_snap_filename()
|
||||||
end
|
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)
|
function config_module.get_config(extension)
|
||||||
local code = visual_utils.get_selected_text()
|
local code = visual_utils.get_selected_text()
|
||||||
local start_line_number = visual_utils.get_start_line_number()
|
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",
|
fonts_folder = assets_folder .. "/fonts",
|
||||||
themes_folder = assets_folder .. "/themes",
|
themes_folder = assets_folder .. "/themes",
|
||||||
theme = "base16-onedark",
|
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,
|
start_line_number = static.config.has_line_number and start_line_number or nil,
|
||||||
}, static.config)
|
}, static.config)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ return {
|
||||||
breadcrumbs_separator = "/",
|
breadcrumbs_separator = "/",
|
||||||
has_breadcrumbs = false,
|
has_breadcrumbs = false,
|
||||||
has_line_number = false,
|
has_line_number = false,
|
||||||
|
show_workspace = false,
|
||||||
min_width = 0,
|
min_width = 0,
|
||||||
},
|
},
|
||||||
cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))),
|
cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))),
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
local string_utils = require("codesnap.utils.string")
|
local string_utils = require("codesnap.utils.string")
|
||||||
local path_utils = {}
|
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)
|
function path_utils.back(path)
|
||||||
local parsed_path, _ = path:gsub("/[^\\/]+/?$", "")
|
local parsed_path, _ = path:gsub("/[^\\/]+/?$", "")
|
||||||
|
|
||||||
return parsed_path
|
return parsed_path
|
||||||
end
|
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()
|
function path_utils.get_relative_path()
|
||||||
local full_file_path = vim.fn.expand("%:p")
|
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
|
end
|
||||||
|
|
||||||
return path_utils
|
return path_utils
|
||||||
|
|
Loading…
Reference in New Issue