Created
March 10, 2012 14:59
-
-
Save ghedo/2011665 to your computer and use it in GitHub Desktop.
Pipe stuff to the browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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