Skip to content

Instantly share code, notes, and snippets.

@dayne
Forked from anildigital/browser
Created May 24, 2011 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayne/988187 to your computer and use it in GitHub Desktop.
Save dayne/988187 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Usage: browser
# pipe html to a browser
# e.g.
# $ echo "<h1>hi mom!</h1>" | browser
# $ ron -5 man/rip.5.ron | browser
if $stdin.tty?
puts <<-usage
Usage: browser
pipe html to a browser
$ echo '<h1>hi mom!</h1>' | browser
$ ron -5 man/rip.5.ron | browser
usage
else
require 'tempfile'
tmp = Tempfile.new(['', '.html'])
File.open(tmp.path, "w+") do |f|
f.puts $stdin.read
end
exec "firefox #{tmp.path}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment