Florian Baumann | 02d65af | 2010-11-10 20:25:40 +0100 | [diff] [blame] | 1 | # based on https://gist.github.com/318247 |
| 2 | |
| 3 | # Usage: browser |
| 4 | # pipe html to a browser |
| 5 | # e.g. |
| 6 | # $ echo "<h1>hi mom!</h1>" | browser |
| 7 | # $ ron -5 man/rip.5.ron | browser |
| 8 | |
| 9 | function browser() { |
| 10 | if [ -t 0 ]; then |
| 11 | if [ -n "$1" ]; then |
| 12 | open $1 |
| 13 | else |
| 14 | cat <<usage |
| 15 | Usage: browser |
| 16 | pipe html to a browser |
| 17 | |
| 18 | $ echo '<h1>hi mom!</h1>' | browser |
| 19 | $ ron -5 man/rip.5.ron | browser |
| 20 | usage |
| 21 | |
| 22 | fi |
| 23 | |
| 24 | else |
| 25 | f="/tmp/browser.$RANDOM.html" |
| 26 | cat /dev/stdin > $f |
| 27 | open $f |
| 28 | fi |
| 29 | } |
Robert Lowe | 63a00c7 | 2011-03-07 23:16:18 -0500 | [diff] [blame] | 30 | |
| 31 | |
| 32 | # pipe hot spicy interwebs into textmate and cleanup! |
| 33 | # |
| 34 | # Usage: wmate |
| 35 | # wget into a pipe into TextMate and force Tidy (you can undo in textmate) |
| 36 | # e.g. |
| 37 | # $ wmate google.com |
| 38 | |
| 39 | function wmate() { |
| 40 | if [ -t 0 ]; then |
| 41 | if [ -n "$1" ]; then |
| 42 | wget -qO- $1 | /usr/bin/mate |
| 43 | |
| 44 | TIDY=`/usr/bin/osascript << EOT |
| 45 | tell application "TextMate" |
| 46 | activate |
| 47 | end tell |
| 48 | |
| 49 | tell application "System Events" |
| 50 | tell process "TextMate" |
| 51 | tell menu bar 1 |
| 52 | tell menu bar item "Bundles" |
| 53 | tell menu "Bundles" |
| 54 | tell menu item "HTML" |
| 55 | tell menu "HTML" |
| 56 | click menu item "Tidy" |
| 57 | end tell |
| 58 | end tell |
| 59 | end tell |
| 60 | end tell |
| 61 | end tell |
| 62 | end tell |
| 63 | end tell |
| 64 | EOT` |
| 65 | |
| 66 | else |
| 67 | cat <<usage |
| 68 | Usage: wmate google.com |
| 69 | wget into a pipe into TextMate and force Tidy (you can undo in textmate) |
| 70 | |
| 71 | $ wmate google.com |
| 72 | usage |
| 73 | |
| 74 | fi |
| 75 | fi |
| 76 | } |
| 77 | |
| 78 | # |
| 79 | # Usage: raw google.com |
| 80 | # wget into a temp file and pump it into your browser |
| 81 | # |
| 82 | # e.g. |
| 83 | # $ raw google.com |
| 84 | function raw() { |
| 85 | if [ -t 0 ]; then |
| 86 | if [ -n "$1" ]; then |
| 87 | wget -qO- $1 | browser |
| 88 | else |
| 89 | cat <<usage |
| 90 | Usage: raw google.com |
| 91 | wget into a temp file and pump it into your browser |
| 92 | |
| 93 | $ raw google.com |
| 94 | usage |
| 95 | fi |
| 96 | fi |
| 97 | } |