parse_desktop_file: rtrim lines before parsing (#1677)
This commit is contained in:
parent
27eba6c034
commit
c1bcad5f5e
|
@ -13,7 +13,6 @@ local utils = require("menubar.utils")
|
||||||
local icon_theme = require("menubar.icon_theme")
|
local icon_theme = require("menubar.icon_theme")
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local string = string
|
|
||||||
local table = table
|
local table = table
|
||||||
|
|
||||||
local menu_gen = {}
|
local menu_gen = {}
|
||||||
|
@ -75,16 +74,6 @@ local function get_category_name_and_usage_by_type(app_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Remove CR\LF newline from the end of the string.
|
|
||||||
-- @param s string to trim
|
|
||||||
local function trim(s)
|
|
||||||
if not s then return end
|
|
||||||
if string.byte(s, #s) == 13 then
|
|
||||||
return string.sub(s, 1, #s - 1)
|
|
||||||
end
|
|
||||||
return s
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Generate an array of all visible menu entries.
|
--- Generate an array of all visible menu entries.
|
||||||
-- @tparam function callback Will be fired when all menu entries were parsed
|
-- @tparam function callback Will be fired when all menu entries were parsed
|
||||||
-- with the resulting list of menu entries as argument.
|
-- with the resulting list of menu entries as argument.
|
||||||
|
@ -120,8 +109,8 @@ function menu_gen.generate(callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if target_category then
|
if target_category then
|
||||||
local name = trim(entry.Name) or ""
|
local name = utils.rtrim(entry.Name) or ""
|
||||||
local cmdline = trim(entry.cmdline) or ""
|
local cmdline = utils.rtrim(entry.cmdline) or ""
|
||||||
local icon = entry.icon_path or nil
|
local icon = entry.icon_path or nil
|
||||||
table.insert(result, { name = name,
|
table.insert(result, { name = name,
|
||||||
cmdline = cmdline,
|
cmdline = cmdline,
|
||||||
|
|
|
@ -119,6 +119,16 @@ local function get_icon_lookup_path()
|
||||||
return icon_lookup_path
|
return icon_lookup_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Remove CR newline from the end of the string.
|
||||||
|
-- @param s string to trim
|
||||||
|
function utils.rtrim(s)
|
||||||
|
if not s then return end
|
||||||
|
if string.byte(s, #s) == 13 then
|
||||||
|
return string.sub(s, 1, #s - 1)
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
--- Lookup an icon in different folders of the filesystem.
|
--- Lookup an icon in different folders of the filesystem.
|
||||||
-- @tparam string icon_file Short or full name of the icon.
|
-- @tparam string icon_file Short or full name of the icon.
|
||||||
-- @treturn string|boolean Full name of the icon, or false on failure.
|
-- @treturn string|boolean Full name of the icon, or false on failure.
|
||||||
|
@ -173,6 +183,7 @@ function utils.parse_desktop_file(file)
|
||||||
-- Parse the .desktop file.
|
-- Parse the .desktop file.
|
||||||
-- We are interested in [Desktop Entry] group only.
|
-- We are interested in [Desktop Entry] group only.
|
||||||
for line in io.lines(file) do
|
for line in io.lines(file) do
|
||||||
|
line = utils.rtrim(line)
|
||||||
if line:find("^%s*#") then
|
if line:find("^%s*#") then
|
||||||
-- Skip comments.
|
-- Skip comments.
|
||||||
(function() end)() -- I haven't found a nice way to silence luacheck here
|
(function() end)() -- I haven't found a nice way to silence luacheck here
|
||||||
|
|
Loading…
Reference in New Issue