Skip to content

Instantly share code, notes, and snippets.

@ghedo
Created March 10, 2012 14:59
Show Gist options
  • Save ghedo/2011665 to your computer and use it in GitHub Desktop.
Save ghedo/2011665 to your computer and use it in GitHub Desktop.
Pipe stuff to the browser
#!/bin/sh -e
# Usage: bpipe [-h|--html]
# Pipe stuff to the browser
if [ -t 0 ]; then
echo "Usage: echo '<h1>some stuff</h1>' | bpipe"
else
opt=`getopt -o h --long html -n bpipe -- "$@"`
eval set -- "$opt"
case "$1" in
-h|--html) temp=`mktemp --suffix=.html` ;;
--) break ;;
esac
if [ -z "$temp" ]; then
temp=`mktemp`
fi
cat /dev/stdin > $temp
sensible-browser $temp # would work with xdg-open and open too
rm $temp
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment