Hello list, I started using menubar since its introduction to awesome git/master, but always felt that it needs to be able to execute commands, which essentially makes it as a replacement for the shell prompt (in the default config execute with Mod4+r). I went and implemented features I needed and here are three patches.
The first implements search in command names of the entries, which does let me launch gimp by entering gimp. The second patch implements the feature I mentioned earlier. And the third patch implements shell completion. Feel free to criticise and make suggestions, I will try to fix the problems. All best, Ignas
>From d39151d4f6413afc3b3a5eb4f7645edfba22656d Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Thu, 3 May 2012 12:43:13 +0100 Subject: [PATCH 1/3] Menubar: Search command and application names. Previously menubar would match only command names. This commit will make it search for the command names as well. This make the menubar more useful for me, as I do not need to write "Image" to get some results for GIMP. I can just write "gimp" it will be found. Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 46942bc..4e3a35d 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -134,12 +134,14 @@ local function menulist_update(query) end end - -- Add the applications + -- Add the applications according to their name and cmdline for i, v in ipairs(menu_entries) do v.focused = false if not current_category or v.category == current_category then - if string.match(v.name, nocase(query)) then - if string.match(v.name, "^" .. nocase(query)) then + if string.match(v.name, nocase(query)) + or string.match(v.cmdline, nocase(query)) then + if string.match(v.name, "^" .. nocase(query)) + or string.match(v.cmdline, "^" .. nocase(query)) then table.insert(shownitems, v) else table.insert(match_inside, v) -- 1.7.8.5
>From 4d08a3ad24064a34588779adb98132bea186ece5 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Thu, 3 May 2012 12:46:16 +0100 Subject: [PATCH 2/3] Menubar: If there are no matches, exec the query. This will make it behave more similarly to a simple shell prompt. This allows you to have only one prompt to launch applications. Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 4e3a35d..d23f199 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -91,9 +91,6 @@ end -- @param o The menu item. -- @return if the function processed the callback, new awful.prompt command, new awful.prompt prompt text. local function perform_action(o) - if not o or o.empty then - return true - end if o.key then current_category = o.key local new_prompt = shownitems[current_item].name .. ": " @@ -161,8 +158,10 @@ local function menulist_update(query) end shownitems[current_item].focused = true else - table.insert(shownitems, { name = "<no matches>", icon = nil, - empty = true }) + table.insert(shownitems, { + name = "Run command: " .. query, + cmdline = query, + icon = nil }) end common.list_update(common_args.w, nil, label, -- 1.7.8.5
>From 11781de2c4f3b969b631c5d0c94e7c53a89b0580 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Thu, 3 May 2012 12:50:09 +0100 Subject: [PATCH 3/3] Menubar: Use shell completion. Since we can search for commands and execute them if no entries are found, why not to use shell completion for it? Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index d23f199..9544988 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -238,10 +238,12 @@ function show(scr) current_item = 1 current_category = nil menulist_update() - prompt.run({ prompt = "Run app: " }, instance.prompt.widget, function(s) end, - nil, awful.util.getdir("cache") .. "/history_menu", nil, hide, - menulist_update, - prompt_keypressed_callback) + prompt.run({ prompt = "Run app: " }, instance.prompt.widget, + function(s) end, -- do not use exe_callback function + awful.completion.shell, -- make use of shell completion + awful.util.getdir("cache") .. "/history_menu", + nil, hide, menulist_update, prompt_keypressed_callback + ) instance.wibox.visible = true end -- 1.7.8.5
