Skip to content

Commit

Permalink
refactor(sources.path): path normalization function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekaboo committed Jan 14, 2025
1 parent c3fe65e commit ed7c686
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lua/dropbar/sources/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ local function convert(path, buf, win)
}))
end

local normalize = vim.fs.normalize
if vim.uv.os_uname().sysname:find('Windows', 1, true) then
local fs_normalize = not vim.uv.os_uname().sysname:find('Windows', 1, true)
and vim.fs.normalize
---Normalize path on Windows, see #174
---In addition to normalizing the path with `vim.fs.normalize()`, we convert
---the drive letter to uppercase.
Expand All @@ -215,14 +215,13 @@ if vim.uv.os_uname().sysname:find('Windows', 1, true) then
---To standardize this, we convert the drive letter to uppercase.
---@param path string full path
---@return string: path with uppercase drive letter
function normalize(path)
or function(path, ...)
return (
string.gsub(vim.fs.normalize(path), '^([a-zA-Z]):', function(c)
string.gsub(vim.fs.normalize(path, ...), '^([a-zA-Z]):', function(c)
return c:upper() .. ':'
end)
)
end
end

---Get list of dropbar symbols of the parent directories of given buffer
---@param buf integer buffer handler
Expand All @@ -232,8 +231,8 @@ end
local function get_symbols(buf, win, _)
local path_opts = configs.opts.sources.path
local symbols = {} ---@type dropbar_symbol_t[]
local current_path = normalize((vim.api.nvim_buf_get_name(buf)))
local root = normalize(configs.eval(path_opts.relative_to, buf, win))
local current_path = fs_normalize((vim.api.nvim_buf_get_name(buf)))
local root = fs_normalize(configs.eval(path_opts.relative_to, buf, win))
while
#symbols < configs.opts.sources.path.max_depth
and current_path
Expand Down

0 comments on commit ed7c686

Please sign in to comment.