Improved .desktop parsing (FS#1057)
When parsing .desktop, we care only about [Desktop Entry] group. Everything else is ignored. Signed-off-by: Arvydas Sidorenko <asido4@gmail.com> Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
56170db631
commit
f57bd595dc
|
@ -124,11 +124,28 @@ end
|
||||||
-- @return A table with file entries.
|
-- @return A table with file entries.
|
||||||
function utils.parse(file)
|
function utils.parse(file)
|
||||||
local program = { show = true, file = file }
|
local program = { show = true, file = file }
|
||||||
|
local desktop_entry = false
|
||||||
|
|
||||||
|
-- Parse the .desktop file.
|
||||||
|
-- We are interested in [Desktop Entry] group only.
|
||||||
for line in io.lines(file) do
|
for line in io.lines(file) do
|
||||||
for key, value in line:gmatch("(%w+)=(.+)") do
|
if not desktop_entry and line == "[Desktop Entry]" then
|
||||||
|
desktop_entry = true
|
||||||
|
else
|
||||||
|
if line:sub(1, 1) == "[" and line:sub(-1) == "]" then
|
||||||
|
-- A declaration of new group - stop parsing
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Grab the values
|
||||||
|
for key, value in line:gmatch("(%w+)%s*=%s*(.+)") do
|
||||||
program[key] = value
|
program[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- In case [Desktop Entry] was not found
|
||||||
|
if not desktop_entry then return nil end
|
||||||
|
|
||||||
-- Don't show program if NoDisplay attribute is false
|
-- Don't show program if NoDisplay attribute is false
|
||||||
if program.NoDisplay and string.lower(program.NoDisplay) == "true" then
|
if program.NoDisplay and string.lower(program.NoDisplay) == "true" then
|
||||||
|
@ -183,7 +200,10 @@ function utils.parse_dir(dir)
|
||||||
local programs = {}
|
local programs = {}
|
||||||
local files = io.popen('find '.. dir ..' -maxdepth 1 -name "*.desktop" 2>/dev/null')
|
local files = io.popen('find '.. dir ..' -maxdepth 1 -name "*.desktop" 2>/dev/null')
|
||||||
for file in files:lines() do
|
for file in files:lines() do
|
||||||
table.insert(programs, utils.parse(file))
|
local program = utils.parse(file)
|
||||||
|
if program then
|
||||||
|
table.insert(programs, program)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return programs
|
return programs
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue