ssh plugin: added option to ask for a username in addition to the host
[wmiirc-lua.git] / plugins / browser.lua
blob8465b9ef972c47bd753a585604c0333140d43500
1 --
2 -- Copyright (c) 2007, Bart Trojanowski <bart@jukie.net>
3 --
4 -- Browser integration for wmii.
5 --
6 -- This plugin depends on xclip utility.
7 --
9 local wmii = require("wmii")
10 local os = require("os")
11 local string = require("string")
12 local tostring = tostring
13 local type = type
15 module ("browser")
16 api_version=0.1
18 -- configuration defaults
20 wmii.set_conf ("browser", "firefox")
22 -- new handlers
24 wmii.add_action_handler ("browser", function (act, args)
25 local url = ""
26 if type(args) == "string" then
27 -- create an quoted string, with quotes in the argument escaped
28 url = args:gsub("^%s*",""):gsub("%s*$","")
29 url = "'" .. url:gsub("'", "\\'") .. "'"
30 else
31 -- TODO: need to escape this
32 url = '"`xclip -o`"'
33 end
34 local browser = wmii.get_conf ("browser") or "x-www-browser"
35 local cmd = browser .. " " .. url .. " &"
36 wmii.log (" executing: " .. cmd)
37 os.execute (cmd)
38 end)
40 wmii.add_action_handler ("google", function (act, args)
41 local search = ""
42 if type(args) == "string" then
43 -- create an quoted string, with quotes in the argument escaped
44 search = args:gsub("^%s*",""):gsub("%s*$","")
45 search = search:gsub("'", "\\'")
46 else
47 -- TODO: need to escape this
48 search = '`xclip -o`'
49 end
50 local browser = wmii.get_conf ("browser") or "x-www-browser"
51 local cmd = browser .. " \"http://google.com/search?q=" .. search .. "\" &"
52 wmii.log (" executing: " .. cmd)
53 os.execute (cmd)
54 end)