On 03/31/2012 06:07 AM, alan moore wrote:
Greetings!
I am trying to work out how to hack the run dialog in awesome so that
it can handle URLs. Basically, I want it to detect when I type in any
kind of URL and pass it to xdg-open.
I have a pretty good idea of how that actual bit of code should look,
but what's the simplest way to override the default callback without
having to reinvent the wheel, and without damaging the existing
functionality (including command completion, etc)?
That is fairly easy to do. Search your rc.lua for this:
awful.key({ modkey }, "r", function ()
local promptbox =
mypromptbox[mouse.screen]
awful.prompt.run({ prompt =
promptbox.prompt },
promptbox.widget,
function (...)
local result =
awful.util.spawn(...)
if type(result)
== "string" then
promptbox.widget:set_text(result)
end
end,
awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
Look at the argument that are being passes to `awful.prompt.run`. Here
they are in order:
1. Options table (for configuring prompt text, colors etc.)
2. The promptbox widget to run the prompt onto (instance of
awful.widget.prompt).
3. Exec callback - a function that will be called when the user presses
Return. The function recieves the input string as the argument.
4. A function that will try to complete the command on Tab.
5. A file where the history of the entered commands should be saved to
(and taken from, of course).
So what you need is to modify the exec callback function. Since URL must
contain at least one dot and linux commands generally don't, you can
come up with something like this (haven't tried if it works):
function (comm)
if comm:match("%.") then
awful.util.swapn('xdg-open "' .. comm .. '"')
else
local result = awful.util.spawn(...)
if type(result) == "string" then
promptbox.widget:set_text(result)
end
end
end
Regards,
Alexander
--
To unsubscribe, send mail to awesome-unsubscr...@naquadah.org.