-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
44 lines (36 loc) · 951 Bytes
/
utils.lua
File metadata and controls
44 lines (36 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local PATH = (...):gsub("%.utils$", "")
local inspect = require(PATH .. ".lib.inspect")
local function get_current_dir()
local is_windows = package.config:sub(1, 1) == "\\"
local cmd = is_windows and "cd" or "pwd"
local p = io.popen(cmd)
if not p then
return ""
end
local dir = p:read("*l")
p:close()
return dir
end
local function format(...)
return inspect(..., { newline = "\n", indent = "\t" })
end
-- helper to wrap methods
---@param tbl table
---@param methodName string
---@param callback fun(...: any)
local function wrapWith(tbl, methodName, callback)
local original = tbl[methodName]
tbl[methodName] = function(self, ...)
callback(methodName, ...)
return original(self, ...)
end
end
local function startsWith(str, value)
return string.sub(str, 1, string.len(value)) == value
end
return {
get_current_dir = get_current_dir,
format = format,
wrapWith = wrapWith,
startsWith = startsWith,
}