Skip to content

Instantly share code, notes, and snippets.

@n0coast
Forked from defunkt/browser
Last active December 5, 2022 04:12
Show Gist options
  • Select an option

  • Save n0coast/bd95a4d7d06aff0159fcf98fb6fcc44a to your computer and use it in GitHub Desktop.

Select an option

Save n0coast/bd95a4d7d06aff0159fcf98fb6fcc44a to your computer and use it in GitHub Desktop.
pipe html to a browser

Installation:

sudo curl https://gist.githubusercontent.com/n0coast/bd95a4d7d06aff0159fcf98fb6fcc44a/raw/e24e42d9d14c70f5be4ce2b385f1c42f62ace7a4/browser -o /usr/local/bin/browser
sudo chmod +x /usr/local/bin/browser

Usage:

echo '<h1>hi mom!</h1>' | browser

a tool like marked can parse markdown which can be passed to browser to quickly render and view output from tools like helm show readme, for example: helm show readme bitnami/rabbitmq | marked | browser

#!/bin/sh -e
#
# Usage: browser
# pipe html to a browser
# e.g.
# $ echo '<h1>hi mom!</h1>' | browser
case "$(uname -s)" in
Linux) open_command=xdg-open;;
*) open_command=open;;
esac
if [ -t 0 ]; then
if [ -n "$1" ]; then
$open_command $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_command $f
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment