aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-25 09:03:51 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-25 09:03:51 +1200
commit56c99d1c74286d22a79b78ad3c64855af7d4ea4b (patch)
treeb3ff0c7164f3de9a820139b77c7a40dcec576cb0
parentOpen PDFs with xpdf(1) (diff)
downloaddotfiles-56c99d1c74286d22a79b78ad3c64855af7d4ea4b.tar.gz
dotfiles-56c99d1c74286d22a79b78ad3c64855af7d4ea4b.zip
Tidy up and comment xgo(1)
-rwxr-xr-xbin/xgo37
1 files changed, 28 insertions, 9 deletions
diff --git a/bin/xgo b/bin/xgo
index 828eba5a..a6489855 100755
--- a/bin/xgo
+++ b/bin/xgo
@@ -11,44 +11,63 @@ for url ; do (
# 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
- ;;
- https://github.com/*/blob/*)
+
+ # If it's a GitHub link, swap "blob" for "raw" to get the actual file
+ *://github.com/*/blob/*)
url=$(printf '%s\n' "$url" | sed 's_/blob/_/raw/_')
;;
+
+ # If it's a not-direct imgur link and not to an album, swap URL
+ # elements to get to the actual file (it may not actually be a JPEG;
+ # the MIME type will tell us)
+ *://imgur.com/a/*) ;;
*://imgur.com/*)
url=$(printf '%s\n' "$url" | sed 's_imgur\.com_i.imgur.com_;s/$/.jpg/')
;;
+
+ # If it's a YouTube video without a given start time, load it in mpv(1)
+ *[/.]youtube.com/watch*[?\&]t=) ;;
+ *[/.]youtube.com/watch*)
+ mpv -- "$url" && exit
+ ;;
esac
# Get the MIME type data
mt=$(urlmt "$url")
- # If the MIME type is an image, load it in feh(1)
+ # Switch on media type
case $mt in
+
+ # Open PDFs in xpdf(1); download them first as xpdf(1) doesn't seem to
+ # have a way to handle stdin files
application/pdf)
(
cd -- "$HOME"/Downloads || exit
curl -O -- "$url" || exit
- xpdf -- "${url##*/}" || exit
+ xpdf -- "${url##*/}"
) && exit
;;
+
+ # Open audio and video in mpv(1); force a window even for audio so I
+ # can control it
audio/*|video/*)
mpv --force-window -- "$url" && exit
;;
+
+ # If the MIME type is an image that is not a GIF, load it in feh(1)
image/gif) ;;
image/*)
curl -- "$url" | feh - && exit
;;
+
+ # Open plain text in a terminal view(1)
text/plain)
# shellcheck disable=SC2016
- urxvt -e sh -c 'curl -- "$1" | view -' \
- _ "$url" && exit
+ urxvt -e sh -c 'curl -- "$1" | view -' _ "$url" && exit
;;
esac
# Otherwise, just pass it to br(1)
br "$url"
+
) & done