1 local awful = require ("awful")
2 local naughty = require ("naughty")
4 local selection = selection
10 config.open_in_term = nil
12 -- Many of what's used here should have been loaded already!
13 local spawn = awful.util.spawn
14 local gsub = string.gsub
15 local match = string.match
17 local xbrowser="xdg-open"
18 local term_browser="w3m"
20 -- {{{ Helper functions
22 local function url_encode (str)
24 local function repchar (c)
25 return string.format ("%%%02X", string.byte (c))
27 str = gsub (str, "\n", "\r\n")
28 str = gsub (str, "([^%w ])", repchar)
29 str = gsub (str, " ", "+")
34 local function prmpt (prompt_text, cache, fun)
36 function (from_selection)
37 -- Let's check it now, for now:
38 if not config.prompt or not config.open_in_term then
39 naughty.notify ({ text = "Links module is not properly configured!" })
43 if from_selection then
44 local str = selection ()
46 naughty.notify ({ text = "Need a selection!" })
51 config.prompt (prompt_text, fun, nil, cache)
58 -- {{{ Hack for some publishing site at verimag...
60 -- Basic check: we have an adress:
61 local function is_an_uri (str) return match (str, "^[^/]*://[^/]+.*$") end
63 local function open_gate6_link (uri)
64 local function append_host (hostname, to_append)
65 return gsub (hostname, "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2")
68 if not is_an_uri (uri) then
69 naughty.notify ({ text = "Need a valid URI!" })
73 local cmd = xbrowser.." \""..append_host (uri, ".gate6.inist.fr").."\""
74 naughty.notify ({ text = cmd })
78 query_open_gate6_link =
79 prmpt ("Address: ", nil, open_gate6_link)
83 --{{{ Translations and language tools...
85 function find_translation (langs, from_selection)
87 awful.util.getdir ("cache").."/history_transl_"..langs,
89 config.open_in_term (term_browser.." \"http://www.wordreference.com/"..
90 langs.."/"..string.."\"")
96 awful.util.getdir ("cache").."/history_conj_fr",
98 config.open_in_term (term_browser..
99 " \"http://leconjugueur.com/php5/index.php?v="..
100 url_encode (string).."\"")
103 function find_synonym (lang, from_selection)
108 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 config.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)