aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-14 14:25:24 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-14 14:25:24 +1200
commit4c85039f0315132b96abc219fd49862ef4d195de (patch)
treef8b75fed64ce8a51cd706a783283e5629c15dbbd
parentAdd urlh(1) and urlmt(1) (diff)
downloaddotfiles-4c85039f0315132b96abc219fd49862ef4d195de.tar.gz
dotfiles-4c85039f0315132b96abc219fd49862ef4d195de.zip
Add tentative enhancements to br(1)
-rw-r--r--README.markdown3
-rwxr-xr-xbin/br23
-rw-r--r--man/man1/br.112
3 files changed, 32 insertions, 6 deletions
diff --git a/README.markdown b/README.markdown
index 60f68df4..3b5ecb8d 100644
--- a/README.markdown
+++ b/README.markdown
@@ -330,7 +330,8 @@ Installed by the `install-bin` target:
* `ax(1)` evaluates an awk expression given on the command line; this is
intended as a quick way to test how Awk would interpret a given expression.
* `bel(1)` prints a terminal bell character.
-* `br(1)` launches $BROWSER.
+* `br(1)` launches $BROWSER, or a more suitable application for an URL if it
+ knows of one.
* `ca(1)` prints a count of its given arguments.
* `cf(1)` prints a count of entries in a given directory.
* `clrd(1)` sets up a per-line file read, clearing the screen first.
diff --git a/bin/br b/bin/br
index 1d982c04..e2a746c1 100755
--- a/bin/br
+++ b/bin/br
@@ -1,3 +1,24 @@
#!/bin/sh
-# Launch $BROWSER
+# Probably launch $BROWSER, but try a few shortcuts first
+
+# Get the URL and its MIME type
+url=$1
+mt=$(urlmt "$url")
+
+# If the MIME type is an image, load it in feh(1)
+case $mt in
+ image/*)
+ curl -- "$url" | feh - && exit
+ ;;
+esac
+
+# If it's a YouTube video without a given start time, load it in mpv(1)
+case $url in
+ *youtube.com/watch*[?\&]t=) ;;
+ *youtube.com/watch*)
+ mpv -- "$url" && exit
+ ;;
+esac
+
+# Otherwise, just ask $BROWSER to handle it
exec "$BROWSER" "$@"
diff --git a/man/man1/br.1 b/man/man1/br.1
index 5d4d928b..ad841750 100644
--- a/man/man1/br.1
+++ b/man/man1/br.1
@@ -12,10 +12,14 @@ BROWSER=firefox
.B br
.SH DESCRIPTION
.B br
-execs the program in the $BROWSER environment variable. That's it. It was
-written so the browser could safely be launched from xbindkeys(1) and similar
-programs.
+run with no arguments just execs the program in the $BROWSER environment
+variable. If given a single URL, it tries to get its MIME type from a HEAD
+request and matches on the URL and/or the MIME type to see if any more suitable
+programs could open it. Otherwise, it falls back on $BROWSER.
+.P
+At the time of writing, it tries to load image types with feh(1), and YouTube
+URLs without a start time with mpv(1).
.SH SEE ALSO
-brxs(1)
+brxs(1), urlh(1), urlmt(1), feh(1), mpv(1)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>