added pipe-able browser hack from defunkt
authorFlorian Baumann <flo@noqqe.de>
Wed, 10 Nov 2010 19:25:40 +0000 (20:25 +0100)
committerFlorian Baumann <flo@noqqe.de>
Wed, 10 Nov 2010 19:25:40 +0000 (20:25 +0100)
plugins/browser.plugin.bash [new file with mode: 0644]

diff --git a/plugins/browser.plugin.bash b/plugins/browser.plugin.bash
new file mode 100644 (file)
index 0000000..6de184c
--- /dev/null
@@ -0,0 +1,29 @@
+# based on https://gist.github.com/318247
+
+# Usage: browser
+# pipe html to a browser
+# e.g.
+# $ echo "<h1>hi mom!</h1>" | browser
+# $ ron -5 man/rip.5.ron | browser
+
+function 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
+}