blob: 07be40393908fa8bcc320c03eec758987c96a492 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/bin/sh
# lh: the Link Handler
# takes one path or URL as its argument, launches the appropriate program for it
# set argument 1 to stdin if there are no args
if [ $# -eq 0 ]
then
set -- "$(cat)"
fi
# 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
IFS=$2
set -- $1
printf '%s\n' "$@"
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 "$(cat)")
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
}
# while loop for multiple urls
while [ $# -ne 0 ]
do
# handle redirects. tr removes control characters, so the case statement below works as expected.
URL="$(echo "$1"|findredir|tail -1|tr -d '[:cntrl:]')"
# if there were no redirects, just set URL to the first argument
[ -z "$URL" ] && URL="$1"
case "$URL" in
gemini://*|gopher://*)
"$TERMINAL" -e bombadillo "$URL" ;;
*.mov*|*.mkv*|*.webm*|*.mp4*)
mpv --no-terminal "$URL" & ;;
*invidio.us/watch*|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*|*clips.twitch.tv*|*streamable.com*)
yw "$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*|*.jp[eg]*|*.gif*)
IMGPATH="/tmp/$(lstrip "$URL" "*/")"
curl -sL "$URL" > "$IMGPATH" &&
sxiv -pqa "$IMGPATH" & ;;
*.mp3*|*.m4a*|*.flac*|*.aiff*|*.opus*|*.ogg*|*.wav*)
$TERMINAL -e mpv "$URL"& ;;
*.epub*|*.pdf*|*.djvu*)
BOOKPATH="/tmp/$(lstrip "$URL" "*/")"
if [ -n "$READER" ]; then
curl -sL "$URL" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
else
curl -sL "$URL" >"$BOOKPATH" &
fi ;;
*)
if [ -f "$URL" ]; then
op "$URL"
else
"$BROWSER" "$URL" >/dev/null 2>&1 &
fi ;;
esac
shift
done
|