local M = { dsp = {} } ---@param entryfile string ---@param action? string ---@param rules? table 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