You are not logged in.
Hey guys,
I wanted a lightweight browser and after trying many (midori, xombrero, qupzilla, jumanji, dillo), I settled on luakit (+ privoxy). I use my keyboard for most tasks, so it's no surprise that my loyalties are towards awesome and, henceforth, the equally customizable and vimperator-inspired luakit! Vim is my favorite text editor, so getting my luakit experience to seamlessly blend with the rest of my work is one of my priorities.
This is hardly an original contribution, but I thought it would be useful for anybody new to luakit and facing the same problem I was. I searched online but wasn't able to find an effective way to open files externally (videos, pictures and pdfs) apart from this, but it requires using the mouse, which to me, feels a bit awkward.
luakit fortunately has key-bindings borrowed from vimperator that allow users to "follow" links. Usually 'F' and 'Shift+F' serve most purposes (these open a link in the current tab and a new tab respectivey). Similar functionality can be achived using the ';' key followed by another key to "do things" with the selected link. For example, following ';' with say 'Y' allows users to yank urls. Following ';' with 'O' opens the link in the current tab.
My idea was to connect ';' with another key, say 'd', to instruct luakit to use external applications to open the selected link. Adding the following to the end of your 'binds.lua' achieves just this:
add_binds("ex-follow", {
-- Yank element uri to open in an external application
key({}, "d", [[Hint all links (as defined by the `follow.selectors.uri`
selector) and set the primary selection to the matched elements URI,
so that an external app can open it]],
function (w)
w:set_mode("follow", {
prompt = "video", selector = "uri", evaluator = "uri",
func = function (uri)
assert(type(uri) == "string")
uri = string.gsub(uri, " ", "%%20")
luakit.selection.primary = uri
if string.match(uri, "youtube") then
luakit.spawn(string.format("mpv %s", uri))
w:notify("trying to play file on mpv " .. uri)
elseif string.match(uri, "vimeo") then
luakit.spawn(string.format("mpv %s", uri))
w:notify("trying to play file on mpv " .. uri)
elseif string.match(uri, "vine") then
luakit.spawn(string.format("mpv %s", uri))
w:notify("trying to play file on mpv " .. uri)
elseif string.match(uri, "pdf" or "PDF") then
luakit.spawn(string.format("~/.config/scripts/pdfFromURL %s", uri))
w:notify("trying to read file via zathura ")
elseif string.match(uri, "jpg") then
luakit.spawn(string.format("feh -x %s", uri))
w:notify("file contains jpg " )
else
luakit.spawn(string.format("feh -x %s.jpg", uri))
w:notify("no jpg extension | unrecognized")
end
end
})
end),
})
Adding this allows you to use the follow mode with keystrokes ';' and 'd' and once a selection is made, it opens one of the above mentioned external applications. For instance, youtube,vimeo and vine links are opened via mpv (which is a sweet-sweet video player; this also does away with the requirement to use flash for most videos and the prayers for a html5 video to play!). PDFs are opened via zathura. Now, zathura cannot open http links automatically, so the file needs to be downloaded to some temporary location and then opened by zathura. I've written this routine in a small script called pdfFromURL, which can be saved where ever you wish (I've saved it in ~/.config/scripts). This is pdfFromURL:
url=$1
file="${url##*/}"
echo $file
case "$file" in
*\%20* )
urxvtc -e aria2c --allow-overwrite=true -d /var/tmp $url -o lousy_file_name_that_had_spaces.pdf
zathura /var/tmp/lousy_file_name_that_had_spaces.pdf
# echo "found a damned space in file name!"
;;
*)
urxvtc -e aria2c --allow-overwrite=true -d /var/tmp $url
zathura /var/tmp/$file
;;
esac
The above script uses aria2c, zathura and urxvtc. This can be modified as per your requirements.
The picture opening really isn't necessary, but is kind of useful for sites like reddit.
luakit is a really cool browser for being so accessible to costumization (I've never written a single line of lua code previously)!
I hope this post helps at least one other person.
Cheers!
Last edited by cable (2015-05-14 21:46:29)
Offline
nice, exactly what i was looking for. i don't know why you would want to open the url in feh with a jpg extension in the fallthrough case.
other than that, thanks!
Offline
nice, exactly what i was looking for. i don't know why you would want to open the url in feh with a jpg extension in the fallthrough case.
other than that, thanks!
You're right! Don't know why I left that in there!
The fallthrough should read:
else
w:notify("unrecognized format")
end
Offline