Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created March 1, 2010 10:01
Show Gist options
  • Save defunkt/318247 to your computer and use it in GitHub Desktop.
Save defunkt/318247 to your computer and use it in GitHub Desktop.
pipe html to a browser
#!/bin/sh -e
#
# Usage: browser
# pipe html to a browser
# e.g.
# $ echo '<h1>hi mom!</h1>' | browser
# $ ron -5 man/rip.5.ron | browser
if [ -t 0 ]; then
if [ -n "$1" ]; then
open $1
else
cat <<usage
Usage: browser
pipe html to a browser
$ echo '<h1>hi mom!</h1>' | browser
$ ron -5 man/rip.5.ron | browser
usage
fi
else
f="/tmp/browser.$RANDOM.html"
cat /dev/stdin > $f
open $f
fi
@csonuryilmaz
Copy link

It's still working after ~10 years. 😊 Thanks!

Installed with brew install browser 👉 Tested on MacOS Mojave 10.14.6 👍

@benwoodward
Copy link

Works perfectly! Thanks Chris. Oh.. and thanks for making Github! 🙂

@iMichka
Copy link

iMichka commented May 27, 2021

Small heads up for an improvement: open can be replaced by xdg-open to make this work on Linux. Maybe the script could detect if it is used on Mac/Linux and use the correct command based on that.

@ernstki
Copy link

ernstki commented Sep 24, 2022

Small heads up for an improvement: open can be replaced by xdg-open to make this work on Linux. Maybe the script could detect if it is used on Mac/Linux and use the correct command based on that.

Here's @geoff-nixon's version as a standalone Bash script, with support already baked in for Quick Look or some other previewer. Requires bash to be somewhere in the search path if you're on Mac; should mostly work on Linux, too.

@bfontaine
Copy link

Note this was removed from Homebrew in January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment