-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.lua
37 lines (36 loc) · 1.08 KB
/
util.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
-- combine two path
function getPathAbsolute(path1, path2)
return hs.fs.pathToAbsolute(string.format("%s/%s",path1,path2))
end
--get user home dir file
function getUserFilePathhAbsolute(path)
return hs.fs.pathToAbsolute(string.format("%s/%s",os.getenv('HOME'),path))
end
-- a filter that returns true if the given file should be ignored
function ignored(file)
if file == nil then return true end
local _, filename, _ = splitPath(file)
-- ignore dotfiles
if filename:match('^%.') then return true end
return false
end
-- Return true if the file exists, else false
function exists(name)
local f = io.open(name,'r')
if f ~= nil then
io.close(f)
return true
else
return false
end
end
-- Splits a string by '/', returning the parent dir, filename (with extension),
-- and the extension alone.
function splitPath(file)
local parent = file:match('(.+)/[^/]+$')
if parent == nil then parent = '.' end
local filename = file:match('/([^/]+)$')
if filename == nil then filename = file end
local ext = filename:match('%.([^.]+)$')
return parent, filename, ext
end