From ba0d8e38e5bcac99b2d643dd581fb89380ff4a4e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 27 Sep 2015 18:01:18 +0200 Subject: [PATCH] awful.prompt.run: handle command return value from hooks --- lib/awful/prompt.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index 413f3820f..9c16dc960 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -228,6 +228,9 @@ end -- @tparam[opt] table args.hooks The "hooks" argument uses a syntax similar to -- `awful.key`. It will call a function for the matching modifiers + key. -- It receives the command (widget text/input) as an argument. +-- If the callback returns a command, this will be passed to the +-- `exe_callback`, otherwise nothing gets executed by default, and the hook +-- needs to handle it. -- hooks = { -- -- Apply startup notification properties with Shift-Return. -- {{"Shift" }, "Return", function(command) @@ -238,10 +241,8 @@ end -- -- with ":" in a terminal. -- {{}, "Return", function(command) -- if command:sub(1,1) == ":" then --- command = terminal .. ' -e ' .. command:sub(2) +-- return terminal .. ' -e ' .. command:sub(2) -- end --- mypromptbox[awful.screen.focused()]:spawn_and_handle_error( --- command) -- end} -- } -- @param textbox The textbox to use for the prompt. @@ -365,7 +366,16 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa match = match and mod[v2] end if match or #modifiers == 0 then - exec(v[3]) + local cb + local ret = v[3](command) + if ret then + command = ret + cb = exe_callback + else + -- No callback. + cb = function() end + end + exec(cb) return end end