Merge pull request #29 from kyazdani42/fix-lua-path-matching
fix lua path matching again
This commit is contained in:
commit
0d77ba683d
@ -1,3 +1,4 @@
|
|||||||
|
local utils = require'lib.utils'
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local roots = {}
|
local roots = {}
|
||||||
@ -26,10 +27,6 @@ function M.reload_roots()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function path_to_matching_str(path)
|
|
||||||
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)')
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_git_root(path)
|
local function get_git_root(path)
|
||||||
if roots[path] then
|
if roots[path] then
|
||||||
return path, roots[path]
|
return path, roots[path]
|
||||||
@ -37,7 +34,7 @@ local function get_git_root(path)
|
|||||||
|
|
||||||
for name, status in pairs(roots) do
|
for name, status in pairs(roots) do
|
||||||
if status ~= not_git then
|
if status ~= not_git then
|
||||||
if path:match(path_to_matching_str(name)) then
|
if path:match(utils.path_to_matching_str(name)) then
|
||||||
return name, status
|
return name, status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -65,7 +62,7 @@ function M.update_status(entries, cwd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local matching_cwd = path_to_matching_str(git_root..'/')
|
local matching_cwd = utils.path_to_matching_str(git_root..'/')
|
||||||
for _, node in pairs(entries) do
|
for _, node in pairs(entries) do
|
||||||
local relpath = node.absolute_path:gsub(matching_cwd, '')
|
local relpath = node.absolute_path:gsub(matching_cwd, '')
|
||||||
if node.entries ~= nil then
|
if node.entries ~= nil then
|
||||||
@ -77,7 +74,7 @@ function M.update_status(entries, cwd)
|
|||||||
if status then
|
if status then
|
||||||
node.git_status = status
|
node.git_status = status
|
||||||
elseif node.entries ~= nil then
|
elseif node.entries ~= nil then
|
||||||
local matcher = '^'..path_to_matching_str(relpath)
|
local matcher = '^'..utils.path_to_matching_str(relpath)
|
||||||
for key, _ in pairs(git_status) do
|
for key, _ in pairs(git_status) do
|
||||||
if key:match(matcher) then
|
if key:match(matcher) then
|
||||||
node.git_status = 'dirty'
|
node.git_status = 'dirty'
|
||||||
|
|||||||
@ -7,9 +7,7 @@ local luv = vim.loop
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function path_to_matching_str(path)
|
local path_to_matching_str = require'lib.utils'.path_to_matching_str
|
||||||
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)')
|
|
||||||
end
|
|
||||||
|
|
||||||
local function dir_new(cwd, name)
|
local function dir_new(cwd, name)
|
||||||
local absolute_path = cwd..'/'..name
|
local absolute_path = cwd..'/'..name
|
||||||
|
|||||||
7
lua/lib/utils.lua
Normal file
7
lua/lib/utils.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.path_to_matching_str(path)
|
||||||
|
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)'):gsub('(%_)', '(%%_)')
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Loading…
Reference in New Issue
Block a user