#!/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 |
This comment has been minimized.
This comment has been minimized.
Just in case anyone can't figure this out: |
This comment has been minimized.
This comment has been minimized.
Small point, but "...hi mom!..." should be '...hi mom!...' in the usage example in the comments. Strong quoting is needed to avoid the dreaded "bash: !: event not found" error. |
This comment has been minimized.
This comment has been minimized.
/Users/humza/homebrew/bin/browser: line 2: syntax error near unexpected token '<' |
This comment has been minimized.
This comment has been minimized.
The URL for installation should be https:
|
This comment has been minimized.
This comment has been minimized.
or with zsh, it is =(foo) takes the output of foo, writes it into a file in /tmp and returns the files path. |
This comment has been minimized.
This comment has been minimized.
In bash you can do |
This comment has been minimized.
This comment has been minimized.
Zeokat usefull piece of code. |
This comment has been minimized.
This comment has been minimized.
Try :; I="$(basename $0)"; [ -z $BROWSER ] && open=open || open=$BROWSER
[ $# -eq 0 ] && set -- -; [ "$1" = "-" ] && [ -t 0 ] &&
echo "Usage: [ COMMAND | $I ] | [ $I < FILE ] | [ $I FILE ... ]" >&2 && exit
for what; do where="/tmp/$(od -N2 < /dev/urandom | openssl dgst -sha1).html"
cat "$what" > "$where" && $open "$where"; sleep 1 && rm -f "$where" & done Some advantages:
Or, you might prefer what I use: avoid leaving your terminal at all, and: cat "$what" > "$where" && qlmanage -p "$where" >/dev/null 2>&1; sleep 1 ... |
This comment has been minimized.
This comment has been minimized.
To show Markdown files in browsers, I found a way without temporary files: https://gist.github.com/Boldewyn/4311962 It uses
|
This comment has been minimized.
This comment has been minimized.
It's still working after ~10 years. Installed with |
This comment has been minimized.
This comment has been minimized.
Works perfectly! Thanks Chris. Oh.. and thanks for making Github! |
This comment has been minimized.
Installation:
Or, if you must: