-
Notifications
You must be signed in to change notification settings - Fork 13
/
helpers.lua
41 lines (35 loc) · 915 Bytes
/
helpers.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
local utils = require('mp.utils')
local self = {}
function self.is_empty(var)
return var == nil or var == '' or (type(var) == 'table' and next(var) == nil)
end
function self.file_exists(filepath)
if not self.is_empty(filepath) then
local info = utils.file_info(filepath)
if info and info.is_file then
return true
end
end
return false
end
function self.alt_dirs()
return {
'/opt/homebrew/bin',
'/usr/local/bin',
utils.join_path(os.getenv("HOME") or "~", '.local/bin'),
}
end
function self.find_executable(name)
local exec_path
for _, path in pairs(self.alt_dirs()) do
exec_path = utils.join_path(path, name)
if self.file_exists(exec_path) then
return exec_path
end
end
return name
end
function self.is_path(str)
return not not string.match(str, '[/\\]')
end
return self