about summary refs log tree commit diff stats
path: root/bin/lh
diff options
context:
space:
mode:
authorensa <psii@riseup.net>2020-06-29 19:45:18 -0700
committerensa <psii@riseup.net>2020-06-29 19:45:18 -0700
commite1d03e2fe607c5e1643be186c4ce4031ae1004e0 (patch)
treeee249107b5fb051f8d11e6c87e2e5e19775c5daa /bin/lh
parenta11f7c357236afea1b00df5f85dc8674f5f1d661 (diff)
downloadcfg-e1d03e2fe607c5e1643be186c4ce4031ae1004e0.tar.gz
bin/fl added, lh reworked, opener renamed, data/applications removed
bin/
	fl: finds links, sends list to dmenu so user can choose one to copy to the
	clipboard
	lh:
		replaced sed invocations with lstrip() invocations
		redir handling changed to function findredir(), which loops over curl's
		output, only outputting location urls
		changed case statement to look for .extensions instead of the end of the url
		local files are now sent to bin/op for processing
		mpv given --no-terminal flag for no output instead of redirection shit
		similarly, sxiv is given -q (and -p to not cache)
	op:
		formerly opener
		changed error message to be more portable
	prompt:
		removed help text
	pw:
		doesn't need to be in a variable
	rsschk:
		redesigned after an eternity
		uses a modified re_urls, looking for .rss and .xml urls
		generally smaller
	shenv:
		uses ${var:=val}
		specifies /bin/sh
	xbg:
		removed .fehbg handling
config/
	aliasrc:
		e and v set TERM to xterm-256color, otherwise vis freaks out
	cwmrc:
		urgencyborder color added (with color1)
		ungroupborder changed to color5
		program list removed
		4-Return set to $TERMINAL
		4S-r rebound to restart
		4-X set to $LOCK
		prompt binds fixed
	dunst/dunstrc:
		icons disabled
	ksh/functions/l.:
		changed to ksh function
		for non-current directories, changes there in a subshell and uses that
		current directory, sending an error message if the directory doesn't exist
	lf/lfrc:
		cmd open removed
		cmd ttmsh fixed
	shrc:
		removed ALTSCR
		added OPENER=op
		IRC_SERVERS_FILE removed
		TODO changed to correct path
		GOCACHE and GOBIN added, self-explanatory
data/
	applications/:
		removed
	mailcap:
		changed to relegate most of its functionality to bin/op
Diffstat (limited to 'bin/lh')
-rwxr-xr-xbin/lh56
1 files changed, 42 insertions, 14 deletions
diff --git a/bin/lh b/bin/lh
index e662589..4332487 100755
--- a/bin/lh
+++ b/bin/lh
@@ -1,10 +1,12 @@
 #!/bin/sh
 # lh: the Link Handler
-# takes one path or URL as its argument, launches the appropriate program for this.
+# takes one path or URL as its argument, launches the appropriate program for it
 
 # if $1 isn't provided, spawn $BROWSER and exit. this allows lh to be used as a pseudo-browser.
 [ -z "$1" ] && exec "$BROWSER"
 #from pure-sh-bible
+
+#splits a string by $2
 split() {
 	set -f
 	old_ifs=$IFS
@@ -14,32 +16,58 @@ split() {
 	IFS=$old_ifs
 	set +f
 }
+#strips from the right end of a string
+lstrip() {
+	printf '%s\n' "${1##$2}"
+}
+
+# redir unwinding
+# prints all redirect locations
+findredir() {
+	#note: for loop turns all whitespace into newlines
+	for line in $(curl -sIL "$1")
+	do
+		# catch is used to find the line after location:
+		if [ -n "$catch" ]
+		then
+			# return caught line
+			echo "$line"
+			# reset catch variable
+			unset -- catch
+		fi
+		# set catch if the current line is location
+		if echo "$line"|grep -Fq 'ocation:'
+		then
+			catch=1
+		fi
+	done
+}
 
 # 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:]')
+URL=$(findredir|tail -1|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 "$URL" ;;
-	*mkv|*webm|*mp4)
-		mpv "$URL" >/dev/null 2>&1 & ;;
+	*.mkv*|*.webm*|*.mp4*)
+		mpv --no-terminal "$URL" & ;;
 	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*)
-		mpv --ytdl "$URL" >/dev/null 2>&1 & ;;
+		mpv --no-terminal --ytdl "$URL" & ;;
 	*twitch.tv/*)
 		STREAMQUAL="$(split "$(streamlink "$URL"|grep 'Available streams')" ", "|\
 			grep -E "[0-9]"|\
 			dmenu -p "choose stream quality for $URL")"
 		streamlink -p mpv $URL $STREAMQUAL >/dev/null 2>&1 & ;;
-	*png|*jpg|*jpe|*jpeg|*gif)
-		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 "$URL" >/dev/null 2>&1 & ;;
-	*epub|*pdf|*djvu)
-		BOOKPATH="/tmp/$(echo "$URL"|sed 's/.*\///')"
+	*.png*|*.jpg*|*.jpe*|*.jpeg*|*.gif*)
+		IMGPATH="/tmp/$(lstrip "$URL" "*/")"
+		curl -sL "$URL" >"$IMGPATH"&&sxiv -pqa "$IMGPATH" & ;;
+	*.mp3*|*.m4a*|*.flac*|*.aiff*|*.opus*|*.ogg*|*.mp3?source*)
+		mpv --no-terminal "$URL"& ;;
+	*.epub*|*.pdf*|*.djvu*)
+		BOOKPATH="/tmp/$(lstrip "$URL" "*/")"
 		if [ -n "$READER" ]; then
 			curl -sL "$URL" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
 		else
@@ -47,7 +75,7 @@ case "$URL" in
 		fi ;;
 	*)
 		if [ -f "$URL" ]; then
-			$TERMINAL -e "${EDITOR:-vi} $URL"
+			op "$URL"
 		else
 			$BROWSER "$URL" >/dev/null 2>&1 &
 		fi ;;