[UP] add many more ion3 cfg -_-, powerfull, and add thinkpad xorg.conf/.Xmodmap,...
[arrow.git] / archlinux_conf / etc / ion3 / query_url.lua
blob7f3aa9ae5112522181884d9a73c4f9cb80b77509
1 -- Prompt for a URL and open it
2 -- Use Opera bookmarks for completion
3 -- (c) Reuben Thomas 2005 (rrt@sc3d.org); released under the GPL
4 --
5 -- Completes on full URL, name of bookmark, or URL with initial http[s]://[www.] stripped
6 --
7 -- Use something like:
8 --
9 -- kpress(MOD2.."F3", 'query_url(_)'),
11 -- The browser defaults to "sensible-browser"; configure below:
13 local browser = "sensible-browser"
16 -- Read Opera bookmarks
17 function readOperaBookmarks ()
18 local bookmarks, names = {}, {}
20 -- Parse bookmarks file
21 -- Make a list of bookmarks and their names for use as completions.
22 -- Also make a map of names to URLs.
23 local f = io.lines (os.getenv ("HOME") .. "/.opera/opera6.adr")
24 local nameTag = "\tNAME="
25 local nameOff = string.len (nameTag) + 1
26 local namePat = "^" .. nameTag
27 local urlTag = "\tURL="
28 local urlOff = string.len (urlTag) + 1
29 local urlPat = "^" .. urlTag
30 local l = f ()
31 while l do
32 if string.find (l, namePat) then
33 local name = string.sub (l, nameOff)
34 l = f ()
35 if string.find (l, urlPat) then
36 local url = string.sub (l, urlOff)
37 table.insert (bookmarks, url)
38 -- TODO: Make the name and stripped URL processing below
39 -- independent of browsing Opera's bookmarks, and add other
40 -- bookmark formats
41 local urlIndex = table.getn (bookmarks)
42 names[name] = urlIndex
43 table.insert (bookmarks, name)
44 local strippedUrl = string.gsub (url, "^https?://", "")
45 strippedUrl = string.gsub (strippedUrl, "^www\.", "")
46 if url ~= strippedUrl then
47 names[strippedUrl] = urlIndex
48 table.insert (bookmarks, strippedUrl)
49 end
50 end
51 else
52 l = f ()
53 end
54 end
56 return bookmarks, names
57 end
59 -- Prompt for a URL, matching by name or URL
60 function query_url (mplex)
61 local bookmarks, names = readOperaBookmarks ()
62 local function handler (mplex, str)
63 -- If str is the name of a URL, get the url instead
64 local index = names[str]
65 if index then
66 str = bookmarks[index]
67 end
68 -- FIXME: Ion needs a standard way of invoking a browser
69 ioncore.exec_on (mplex, browser .. ' "' .. str .. '"')
70 end
71 local function completor (wedln, what)
72 wedln:set_completions (mod_query.complete_from_list (bookmarks, what))
73 end
74 mod_query.query (mplex, "URL: ", nil, handler, completor)
75 end