Move HOME expand/encode into common module

This commit is contained in:
Francesco Abbate
2020-12-19 23:53:29 +01:00
parent 35c87462a6
commit 4401f33c19
2 changed files with 27 additions and 22 deletions
+14
View File
@@ -152,4 +152,18 @@ function common.bench(name, fn, ...)
end
function common.home_encode(text)
local n = #HOME
if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then
return "~" .. text:sub(n + 1)
end
return text
end
function common.home_expand(text)
return text:gsub("^~", HOME)
end
return common