Compare commits

..

2 Commits

Author SHA1 Message Date
Folkert Kevelam
24af2b56e0 Add dirwalk generator 2024-10-12 16:16:38 +02:00
Folkert Kevelam
902001697b Add correct naming for require 2024-10-12 16:16:30 +02:00
2 changed files with 45 additions and 1 deletions

View File

@ -1,5 +1,7 @@
local M = {} local M = {}
local Extension_Map = require"SpecSwitcher.ExtensionMap"
local Config = { local Config = {
test = "hallo" test = "hallo"
} }
@ -15,7 +17,7 @@ function M.setup(opts)
Config[k] = v Config[k] = v
end end
local mapping = require("ExtensionMap"):new() local mapping = Extension_Map:new()
mapping:add("c", {"h", "H", "hh", "HH"}) mapping:add("c", {"h", "H", "hh", "HH"})

View File

@ -91,8 +91,50 @@ function path.Get_Ext( P, Extension_List )
end end
end end
function path.Walk_Up( P )
if P == "/" then
return nil
end
local rev = string.reverse(P)
local start = 1
if P:sub(-1) == "/" then
start = start + 1
end
local slash_first_idx, _ = string.find(rev, "/", start, true)
return string.sub(P, 1, #P - slash_first_idx + 1)
end
function path.Generate_Dir_Walk( Base, Descend_List )
local Descend_Length = #Descend_List
local i = -1
local Base_Dir = Base
function Inner()
if i == Descend_Length then
local Temp_Dir = path.Walk_Up(Base_Dir)
if Temp_Dir ~= nil then
Base_Dir = Temp_Dir
i = -1
end
end
i = i + 1
if i == 0 then
return Base_Dir
elseif i <= Descend_Length then
return Base_Dir .. Descend_List[i]
end
end
return Inner
end
print(path.Common_Root("/home/folkert/Documents/Projects","/home/folkert/Downloads/sub/sub2/sub3/sub4/hello.txt")) print(path.Common_Root("/home/folkert/Documents/Projects","/home/folkert/Downloads/sub/sub2/sub3/sub4/hello.txt"))
print(path.Get_Ext("/home/folkert/Documents/projects.wo.cp", {"o.cp"})) print(path.Get_Ext("/home/folkert/Documents/projects.wo.cp", {"o.cp"}))
for x in path.Generate_Dir_Walk("/home/folkert/", {"include", "src"}) do
print(x)
end
return path return path