On 03/31/2012 02:26 AM, Alexander Yakushev wrote:
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
Thanks for the help; it's working great!
Here's what I came up with eventually:
--defined somewhere near the top
--did this since xdg-open doesn't handle everything
--runners for various protocols
myrunners = {
http = "xdg-open",
ftp = "dolphin",
file = "xdg-open",
vnc = "krdc",
fish = "dolphin",
smb = "dolphin"
}
--snip
--inside of the globalkeys table:
-- Prompt
awful.key({ modkey }, "r", function ()
local promptbox = mypromptbox[mouse.screen]
awful.prompt.run(
{prompt = promptbox.prompt},
promptbox.widget,
function (command)
local protocol = command:match("^(%a+)://")
if protocol then
command = (myrunners[protocol] or
"xdg-open").." " .. command
end
local result = awful.util.spawn(command)
if type(result) == "string" then
promptbox.widget.text = result
end
end,
awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
--
To unsubscribe, send mail to [email protected].