4 -- Many of what's used here should have been loaded already!
5 local spawn = awful.util.spawn
6 local gsub = string.gsub
7 local match = string.match
8 local prompt = awful.prompt.run
10 -- `mypromptbox' should be defined.
12 -- {{{ Helper functions
14 local function open_in_term (command, notify)
16 naughty.notify ({ text = command })
18 spawn (terminal .." -geometry ".. TERM_GEOMETRY .. " -e " .. command)
21 local function url_encode (str)
23 local function repchar (c)
24 return string.format ("%%%02X", string.byte (c))
26 str = gsub (str, "\n", "\r\n")
27 str = gsub (str, "([^%w ])", repchar)
28 str = gsub (str, " ", "+")
33 local function prmpt (prompt_text, cache, fun)
35 function (from_selection)
36 if from_selection then
37 local str = selection ()
39 naughty.notify ({ text = "Need a selection!" })
44 prompt ({ prompt = prompt_text }, mypromptbox[mouse.screen].widget,
50 local xbrowser="firefox"
51 local term_browser="w3m"
55 -- {{{ Hack for some publishing site at verimag...
57 -- Basic check: we have an adress:
58 local function is_an_uri (str) return match (str, "^[^/]*://[^/]+.*$") end
60 local function open_gate6_link (uri)
61 local function append_host (hostname, to_append)
62 return gsub (hostname, "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2")
65 if not is_an_uri (uri) then
66 naughty.notify ({ text = "Need a valid URI!" })
70 local cmd = xbrowser.." \""..append_host (uri, ".gate6.inist.fr").."\""
71 naughty.notify ({ text = cmd })
75 query_open_gate6_link =
76 prmpt ("Address: ", nil, open_gate6_link)
80 --{{{ Translations and language tools...
82 function find_translation (langs, from_selection)
85 awful.util.getdir ("cache").."/history_transl_"..langs,
87 open_in_term (term_browser.." \"http://www.wordreference.com/"..
88 langs.."/"..string.."\"")
95 awful.util.getdir ("cache").."/history_conj_fr",
97 open_in_term (term_browser..
98 " \"http://leconjugueur.com/php5/index.php?v="..
99 url_encode (string).."\"")
102 function find_synonym (lang, from_selection)
107 req = "en/search?b=1&r="
110 -- XXX: Note I have a huge problem with accents in prompts...
112 awful.util.getdir ("cache").."/history_synonym_"..lang,
114 open_in_term (term_browser..
115 " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/"..req..
116 url_encode (string).. "\"")
117 end) (from_selection)