feat: Highlight gitignored files (and fix g:nvim_tree_gitignore) (#268)

This commit is contained in:
Sindre T. Strøm
2021-04-08 22:52:56 +02:00
committed by GitHub
parent 81269a6eba
commit 50d31fb7f3
8 changed files with 224 additions and 52 deletions

View File

@@ -31,6 +31,25 @@ function M.path_split(path)
return path:gmatch('[^'..path_separator..']+'..path_separator..'?')
end
---Get the basename of the given path.
---@param path string
---@return string
function M.path_basename(path)
path = M.path_remove_trailing(path)
local i = path:match("^.*()" .. path_separator)
if not i then return path end
return path:sub(i + 1, #path)
end
---Get a path relative to another path.
---@param path string
---@param relative_to string
---@return string
function M.path_relative(path, relative_to)
local p, _ = path:gsub("^" .. M.path_to_matching_str(M.path_add_trailing(relative_to)), "")
return p
end
function M.path_add_trailing(path)
if path:sub(-1) == path_separator then
return path
@@ -40,7 +59,8 @@ function M.path_add_trailing(path)
end
function M.path_remove_trailing(path)
return path:gsub(path_separator..'$', '')
local p, _ = path:gsub(path_separator..'$', '')
return p
end
M.path_separator = path_separator