From c108ca20e4170076617b6a2dea843c46da8756bb Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Tue, 18 Sep 2007 21:48:51 -0400 Subject: [PATCH] added browser and google actions, updated TODO --- TODO | 12 ++++++----- plugins/browser.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ wmiirc.lua | 1 + 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 plugins/browser.lua diff --git a/TODO b/TODO index dad5f79..c1b36bc 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,13 @@ If you have any suggests I am happy to add them to the list. for 0.2 release - - bundled plugins - - 'browser' - - wmii.setconf("browser", "firefox") - - 'browser' and 'google' actions to go to a browser - - cheat and use xclip + - core + - document supported keyboard commands + - document actions + - document bundled plugins + - contrib//{README,*} directory structure + - version number in the files + - 'make release' target for 0.3 release - core diff --git a/plugins/browser.lua b/plugins/browser.lua new file mode 100644 index 0000000..763c45e --- /dev/null +++ b/plugins/browser.lua @@ -0,0 +1,62 @@ +-- +-- Copyright (c) 2007, Bart Trojanowski +-- +-- Notification area for wmii bar +-- +-- To get a messages use: +-- +-- wmiir xwrite /event msg anything you want to see +-- +-- If you have a script that seldom generates one-line events, you can run: +-- +-- somescript | sed -u 's/^/msg /' | wmiir write /event +-- or +-- ssh remote tail -F log-file | xargs -n1 -i wmiir xwrite /event "msg {}" +-- + +local wmii = require("wmii") +local os = require("os") +local string = require("string") +local tostring = tostring +local type = type + +module ("browser") +api_version=0.1 + +-- configuration defaults + +wmii.set_conf ("browser", "firefox") + +-- new handlers + +wmii.add_action_handler ("browser", function (act, args) + local url = "" + if type(args) == "string" then + -- create an quoted string, with quotes in the argument escaped + url = args:gsub("^%s*",""):gsub("%s*$","") + url = "'" .. url:gsub("'", "\\'") .. "'" + else + -- TODO: need to escape this + url = '"`xclip -o`"' + end + local browser = wmii.get_conf ("browser") or "x-www-browser" + local cmd = browser .. " " .. url .. " &" + wmii.log (" executing: " .. cmd) + os.execute (cmd) +end) + +wmii.add_action_handler ("google", function (act, args) + local search = "" + if type(args) == "string" then + -- create an quoted string, with quotes in the argument escaped + search = args:gsub("^%s*",""):gsub("%s*$","") + search = search:gsub("'", "\\'") + else + -- TODO: need to escape this + search = '`xclip -o`' + end + local browser = wmii.get_conf ("browser") or "x-www-browser" + local cmd = browser .. " \"http://google.com/search?q=" .. search .. "\" &" + wmii.log (" executing: " .. cmd) + os.execute (cmd) +end) diff --git a/wmiirc.lua b/wmiirc.lua index fe2f301..1be4aea 100755 --- a/wmiirc.lua +++ b/wmiirc.lua @@ -70,6 +70,7 @@ wmii.write ("/tagrules", "/XMMS.*/ -> ~\n" wmii.load_plugin ("messages") wmii.load_plugin ("clock") wmii.load_plugin ("dstat_load") +wmii.load_plugin ("browser") -- here are some other examples... -- 2.11.4.GIT