Skip to content

Instantly share code, notes, and snippets.

@LuRsT
Last active November 21, 2015 13:10
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 LuRsT/b93686a2975d7e3ff92a to your computer and use it in GitHub Desktop.
Save LuRsT/b93686a2975d7e3ff92a to your computer and use it in GitHub Desktop.
Browser script to view html code from the terminal to the browser

Browser

Inspired and based off of https://gist.github.com/defunkt/318247, since that script didn't work with my environment, I decided to improve on it.

Requirements

You need to have bash installed, but this was also tested in zsh so feel free to change the hashbang, apart from that the only thing you need to do is to set the $BROWSER environment variable.

$ export BROWSER="firefox" # or "chromium-browser" or "chrome" or any browser you want
#!/bin/bash
if [ -t 0 ]; then
if [ -n "$1" ]; then
$BROWSER $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
file_path="/dev/shm/browser.${RANDOM}.html"
cat /dev/stdin > $file_path
$BROWSER $file_path
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment