Skip to content

Commit

Permalink
menu: fix elimination of null paths; removed whitespaces; closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
lcpz committed Oct 16, 2018
1 parent 4226433 commit 2b74554
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
25 changes: 12 additions & 13 deletions desktop.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@

--[[
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Desktop section
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2009-2015, Antonio Terceiro
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Desktop section
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2009-2015, Antonio Terceiro
--]]

local awful = require("awful")
local theme = require("beautiful")
local utils = require("menubar.utils")
local wibox = require("wibox")

local capi = { screen = screen }
local capi = capi
local io = io
local ipairs = ipairs
local mouse = mouse
local os = os
local string = { format = string.format }
local string = string
local table = table

-- Desktop icons
Expand Down
17 changes: 8 additions & 9 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

--[[
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2009-2015, Antonio Terceiro
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2009-2015, Antonio Terceiro
--]]

return {
Expand Down
39 changes: 16 additions & 23 deletions menu.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@

--[[
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Menu section
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2014, Harvey Mittens
Awesome-Freedesktop
Freedesktop.org compliant desktop entries and menu
Menu section
Licensed under GNU General Public License v2
* (c) 2016, Luke Bonham
* (c) 2014, Harvey Mittens
--]]

local awful_menu = require("awful.menu")
local menu_gen = require("menubar.menu_gen")
local menu_utils = require("menubar.utils")
local icon_theme = require("menubar.icon_theme")
local gls = require("gears.filesystem")

local os = { execute = os.execute,
getenv = os.getenv }
local pairs = pairs
local string = { byte = string.byte,
format = string.format }
local table = { insert = table.insert,
remove = table.remove,
sort = table.sort }
local pairs, string, table, os = pairs, string, table, os

-- Add support for NixOS systems too
table.insert(menu_gen.all_menu_dirs, string.format("%s/.nix-profile/share/applications", os.getenv("HOME")))

-- Remove non existent paths in order to avoid issues
local existent_paths = {}
for k,v in pairs(menu_gen.all_menu_dirs) do
if os.execute(string.format("ls %s >/dev/null 2>&1", v)) then
if gls.is_dir(v) then
table.insert(existent_paths, v)
end
end
Expand All @@ -49,8 +42,8 @@ local menu = {}
-- @param tab a given table
-- @param val the element to search for
-- @return true if the given string is found within the search table; otherwise, false if not
local function has_value (tab, val)
for index, value in ipairs(tab) do
function menu.has_value (tab, val)
for index, value in pairs(tab) do
if val:find(value) then
return true
end
Expand Down Expand Up @@ -80,7 +73,7 @@ function menu.build(args)
for k, v in pairs(entries) do
for _, cat in pairs(result) do
if cat[1] == v.category then
if not has_value(skip_items, v.name) then
if not menu.has_value(skip_items, v.name) then
table.insert(cat[2], { v.name, v.cmdline, v.icon })
end
break
Expand Down

0 comments on commit 2b74554

Please sign in to comment.