Skip to content

Instantly share code, notes, and snippets.

@Happy-Ferret
Forked from Donearm/feh_or_browser.lua
Created June 15, 2018 15:17
Show Gist options
  • Save Happy-Ferret/7d359115aa563b18d2d5ea5f5b2251fb to your computer and use it in GitHub Desktop.
Save Happy-Ferret/7d359115aa563b18d2d5ea5f5b2251fb to your computer and use it in GitHub Desktop.
Open a url with feh, if it leads to an image, or firefox, in all other cases
#!/usr/bin/env lua
---
-- @author Gianluca Fiore
-- @copyright 2012, Gianluca Fiore <[email protected]>
--
--
-- Open a url with feh, if it leads to an image, or firefox, in all
-- other cases. Trivial but very useful with cli newsreaders (like
-- newsbeuter) to quickly preview images and to not have to switch to
-- the browser's desktop for every url
-- Regexp for images
local rImages = ".*%.[jJGgpP][pPiInN][eE]?[gGfF]"
-- exit if not arguments given
if not arg[1] then
os.exit(1)
end
if string.match(arg[1], rImages) then
local f = os.execute('feh ' .. arg[1])
os.exit(0)
else
local b = os.execute('firefox ' .. arg[1])
os.exit(0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment