You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
914 B
27 lines
914 B
local M = { dsp = {} }
|
|
|
|
---@param entryfile string
|
|
---@param action? string
|
|
---@param rules? table<string, string|number|boolean>
|
|
function M.dsp.exec(entryfile, action, rules)
|
|
local file = io.open(entryfile, 'r')
|
|
if file then
|
|
local group_line = action and '[Desktop Action ' .. action .. ']' or '[Desktop Entry]'
|
|
local line
|
|
local cmd
|
|
repeat line = file:read('l')
|
|
until line == group_line
|
|
repeat line = file:read('l')
|
|
if line:sub(1, 5) == 'Exec=' then
|
|
cmd = line:sub(6, -1)
|
|
break
|
|
end
|
|
until not line or (line:sub(1, 1) == '[' and line:sub(-1, -1) == ']')
|
|
cmd = cmd:gsub(' *%%[fFuUdDnNickvm] *', ' ') -- https://specifications.freedesktop.org/desktop-entry/latest-single/#exec-variables
|
|
if cmd then
|
|
return hl.dsp.exec_cmd(cmd, rules)
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|
|
|