-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
48 lines (34 loc) · 1.03 KB
/
utils.lua
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
45
46
47
48
local fs = require 'fs'
local utils = {}
utils.expand = function(path)
return path:gsub('~', os.getenv 'HOME')
end
utils.clone = function(url, path)
local cmd = io.popen('git clone https://github.com/' .. url
.. ' ' .. path .. ' 2>&1')
local output = cmd:read '*all'
cmd:close()
local res = output:split '\n'
res = res[#res - 1]
return not res:startsWith 'fatal: repository'
end
utils.exists = function(url, module)
local plugfolder = utils.expand('~/.local/share/hilbish/petals/' .. (module and 'libs' or 'start')
.. '/' .. url)
local exists = fs.stat(plugfolder)
return exists
end
utils.getmanifest = function (path)
manifile = io.open(path .. '/package.lua')
manifest = manifile:read '*all'
manifile:close()
props = loadstring(manifest)
return props()
end
function string.startsWith(str, start)
return string.sub(str, 1, string.len(start)) == start
end
function utils.addPackage(plugurl)
package.path = package.path .. ';' .. utils.expand('~/.local/share/hilbish/petals/libs/' .. plugurl .. '/?.lua')
end
return utils