aboutsummaryrefslogtreecommitdiff
path: root/bin/xgo
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:06:39 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:46:47 +1200
commitc8ab406749124d2e762ad5cf53963070113afd0f (patch)
tree54c9721a06957ebe7098a211eea803b0230c0f5d /bin/xgo
parentHandle POSIX correctness in ~/.bash_profile (diff)
downloaddotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz
dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/xgo')
-rwxr-xr-xbin/xgo79
1 files changed, 0 insertions, 79 deletions
diff --git a/bin/xgo b/bin/xgo
deleted file mode 100755
index 652d5a14..00000000
--- a/bin/xgo
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/sh
-# Test and open a clipboard URL with an apt program
-
-# Check arguments
-if [ "$#" -eq 0 ] ; then
- printf >&2 'xgo: At least one URL required\n'
-fi
-
-# Iterate over the URL arguments
-for url ; do (
-
- # Look for patterns in the URL that suggest transformations
- case $url in
-
- # If this is a GitHub or GitLab link, swap "blob" for "raw" to get the actual file
- (*://github.com/*/blob/*|*://gitlab.com/*/blob/*)
- url=$(printf '%s\n' "$url" | sed 's_/blob/_/raw/_')
- ;;
-
- # Dig out the plain text for pastebin.com links
- (*://pastebin.com/*)
- # shellcheck disable=SC2016
- url=$(printf '%s\n' "$url" | sed 's_/[A-Za-z0-9][A-Za-z0-9]*$_/raw&_')
- ;;
-
- # If this is 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 this is 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")
-
- # Switch on media type
- case $mt in
-
- # Open PDFs in xpdf(1); download them first as xpdf(1) does not seem to
- # have a way to handle stdin files
- (application/pdf)
- (
- cd -- "$HOME"/Downloads || exit
- curl -O -- "$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
- ;;
- esac
-
- # Otherwise, just pass it to br(1df)
- br "$url"
-
-) & done