local awful = require ("awful") local naughty = require ("naughty") local string = string local selection = selection module ("links") config = {} config.prompt = nil config.open_in_term = nil -- Many of what's used here should have been loaded already! local spawn = awful.util.spawn local gsub = string.gsub local match = string.match local xbrowser="xdg-open" local term_browser="w3m" -- {{{ Helper functions local function url_encode (str) if str then local function repchar (c) return string.format ("%%%02X", string.byte (c)) end str = gsub (str, "\n", "\r\n") str = gsub (str, "([^%w ])", repchar) str = gsub (str, " ", "+") end return str end local function prmpt (prompt_text, cache, fun) return function (from_selection) -- Let's check it now, for now: if not config.prompt or not config.open_in_term then naughty.notify ({ text = "Links module is not properly configured!" }) return nil end if from_selection then local str = selection () if str == "" then naughty.notify ({ text = "Need a selection!" }) else fun (str) end else config.prompt (prompt_text, fun, nil, cache) end end end -- }}} -- {{{ Hack for some publishing site at verimag... -- Basic check: we have an adress: local function is_an_uri (str) return match (str, "^[^/]*://[^/]+.*$") end local function open_gate6_link (uri) local function append_host (hostname, to_append) return gsub (hostname, "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2") end if not is_an_uri (uri) then naughty.notify ({ text = "Need a valid URI!" }) return false end local cmd = xbrowser.." \""..append_host (uri, ".gate6.inist.fr").."\"" naughty.notify ({ text = cmd }) spawn (cmd) end query_open_gate6_link = prmpt ("Address: ", nil, open_gate6_link) -- }}} --{{{ Translations and language tools... function find_translation (langs, from_selection) prmpt ("Word: ", awful.util.getdir ("cache").."/history_transl_"..langs, function (string) config.open_in_term (term_browser.." \"http://www.wordreference.com/".. langs.."/"..string.."\"") end) (from_selection) end find_fr_conj = prmpt ("Verb: ", awful.util.getdir ("cache").."/history_conj_fr", function (string) config.open_in_term (term_browser.. " \"http://leconjugueur.com/php5/index.php?v=".. url_encode (string).."\"") end) function find_synonym (lang, from_selection) local req if lang == "fr" then req = "fr/search?r=" else req = "en/search?b=1&r=" end -- XXX: Note I have a huge problem with accents in prompts... prmpt ("Word: ", awful.util.getdir ("cache").."/history_synonym_"..lang, function (string) config.open_in_term (term_browser.. " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/"..req.. url_encode (string).. "\"") end) (from_selection) end --}}}