Merge pull request #29 from kyazdani42/fix-lua-path-matching

fix lua path matching again
This commit is contained in:
Kiyan Yazdani 2020-06-01 16:08:49 +02:00 committed by GitHub
commit 0d77ba683d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -1,3 +1,4 @@
local utils = require'lib.utils'
local M = {}
local roots = {}
@ -26,10 +27,6 @@ function M.reload_roots()
end
end
local function path_to_matching_str(path)
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)')
end
local function get_git_root(path)
if roots[path] then
return path, roots[path]
@ -37,7 +34,7 @@ local function get_git_root(path)
for name, status in pairs(roots) do
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
end
end
@ -65,7 +62,7 @@ function M.update_status(entries, cwd)
return
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
local relpath = node.absolute_path:gsub(matching_cwd, '')
if node.entries ~= nil then
@ -77,7 +74,7 @@ function M.update_status(entries, cwd)
if status then
node.git_status = status
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
if key:match(matcher) then
node.git_status = 'dirty'

View File

@ -7,9 +7,7 @@ local luv = vim.loop
local M = {}
local function path_to_matching_str(path)
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)')
end
local path_to_matching_str = require'lib.utils'.path_to_matching_str
local function dir_new(cwd, name)
local absolute_path = cwd..'/'..name

7
lua/lib/utils.lua Normal file
View File

@ -0,0 +1,7 @@
local M = {}
function M.path_to_matching_str(path)
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)'):gsub('(%_)', '(%%_)')
end
return M