about summary refs log tree commit diff stats
path: root/bin/lh
diff options
context:
space:
mode:
authorensa <psii@riseup.net>2020-06-26 17:04:50 -0700
committerensa <psii@riseup.net>2020-06-26 17:04:50 -0700
commita11f7c357236afea1b00df5f85dc8674f5f1d661 (patch)
treedfc5c2c7617709ee29803897ce24acd06c71b2e4 /bin/lh
parent310c76b161e680a698995d61b2a741a05b384fbe (diff)
downloadcfg-a11f7c357236afea1b00df5f85dc8674f5f1d661.tar.gz
improved lh, switched to catgirl
bin/
	lh: now resolves link shorteners first, so web browser is used
	less
	catgirl-open.sh: uses tabbed with xterm to put multiple catgirl
	clients on one "window"
	comm-sel: now uses catgirl-open.sh instead of epic5 in xterm
		cordless specifies config dir so non-standard config
		locations will work
		added different x class flags for different TERMINAL
		values
config/
	cwmrc: removed St and tabbed from autogroups, added tabbed-surf
		things generally fixed to accommodate for xterm
		ALTSCR removed
		$SCR invocations now include -u to hide the cursor
		window force-killing uses non-old $() syntax
	ksh/prompt.ksh: uses unicode halfbar instead of
	powerline triangles
		clears formatting at start of PS1 before coloring things
Diffstat (limited to 'bin/lh')
-rwxr-xr-xbin/lh38
1 files changed, 22 insertions, 16 deletions
diff --git a/bin/lh b/bin/lh
index 016b37f..e662589 100755
--- a/bin/lh
+++ b/bin/lh
@@ -15,34 +15,40 @@ split() {
 	set +f
 }
 
-case "$1" in
+# handle redirects. tr removes control characters, so the case statement below works as expected.
+URL=$(curl -IL "$1"|grep '^location: '|tail -1|sed 's/location: //'|tr -d '[:cntrl:]')
+# if there were no redirects, just set URL to the first argument
+[ -z "$URL" ] && URL="$1"
+
+echo $URL
+case "$URL" in
 	gemini://*|gopher://*)
-		$TERMINAL -e bombadillo "$1" ;;
+		$TERMINAL -e bombadillo "$URL" ;;
 	*mkv|*webm|*mp4)
-		mpv "$1" >/dev/null 2>&1 & ;;
+		mpv "$URL" >/dev/null 2>&1 & ;;
 	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*)
-		mpv --ytdl "$1" >/dev/null 2>&1 & ;;
+		mpv --ytdl "$URL" >/dev/null 2>&1 & ;;
 	*twitch.tv/*)
-		STREAMQUAL="$(split "$(streamlink "$1"|grep 'Available streams')" ", "|\
+		STREAMQUAL="$(split "$(streamlink "$URL"|grep 'Available streams')" ", "|\
 			grep -E "[0-9]"|\
-			dmenu -p "choose stream quality for $1")"
-		streamlink -p mpv $1 $STREAMQUAL >/dev/null 2>&1 & ;;
+			dmenu -p "choose stream quality for $URL")"
+		streamlink -p mpv $URL $STREAMQUAL >/dev/null 2>&1 & ;;
 	*png|*jpg|*jpe|*jpeg|*gif)
-		IMGPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
-		curl -sL "$1" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;;
+		IMGPATH="/tmp/$(echo "$URL"|sed "s/.*\\///")"
+		curl -sL "$URL" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;;
 	*mp3|*m4a|*flac|*aiff|*opus|*ogg|*mp3?source*)
-		mpv "$1" >/dev/null 2>&1 & ;;
+		mpv "$URL" >/dev/null 2>&1 & ;;
 	*epub|*pdf|*djvu)
-		BOOKPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
+		BOOKPATH="/tmp/$(echo "$URL"|sed 's/.*\///')"
 		if [ -n "$READER" ]; then
-			curl -sL "$1" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
+			curl -sL "$URL" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
 		else
-			curl -sL "$1" >"$BOOKPATH" &
+			curl -sL "$URL" >"$BOOKPATH" &
 		fi ;;
 	*)
-		if [ -f "$1" ]; then
-			$TERMINAL -e "${EDITOR:-vi} $1"
+		if [ -f "$URL" ]; then
+			$TERMINAL -e "${EDITOR:-vi} $URL"
 		else
-			$BROWSER "$1" >/dev/null 2>&1 &
+			$BROWSER "$URL" >/dev/null 2>&1 &
 		fi ;;
 esac