generated from mistricky/nvim-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] add show_workspace config for display workspace in breadcrumbs
- Loading branch information
Showing
3 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |