A script to use surfraw from the go-to-url dialog box

Manolo Martínez <[email protected]> Mon, 25 Jun 2012 14:00:13 -0400
Newsgroups gmane.comp.web.elinks.user
Message-ID <20120625180013.GA8152@ManoloMartinez>
Hi!

This is a very silly script that allows using surfraw searches from
within elinks. To search for Wargames torrents in piratebay, for
example, one would type "!piratebay wargames". I find this useful, and
maybe some others will, too.

Thanks for elinks!

Manolo

--

_______________________________________________
elinks-users mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-users
hooks.lua (text/plain, 786 B)
-- Using surfraw from elinks. To search using an elvi from the Go to URL dialog box, use the xyntax "!elvi your search terms". E.g., to search for 
-- Wargames torrents in piratebay, type "!piratebay wargames" in the Go to URL dialog box.
-- You need to have surfraw installed, obviously, and your lua install should have io.popen.

function match (prefix, url)
    return string.sub (url, 1, string.len (prefix)) == prefix
end

function tosurfraw (str)
    return "surfraw -p " .. str .. " 2>/dev/null"
end

function goto_url_hook (url, current_url)
    if match ("!", url) then
        sr = tosurfraw (string.sub (url, 2))
        urlfile = io.popen (sr)
        finalurl = urlfile:read('*all')
        urlfile:close()
        return finalurl

    else
        return url
    end
end