-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkhandler
executable file
·46 lines (41 loc) · 1.46 KB
/
linkhandler
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
#!/bin/sh
# Feed script a url or file location.
# If an image, it will view in nsxiv,
# if a video or gif, it will view in mpv
# if a music file or pdf, it will download,
# otherwise it opens link in browser.
# If no url given. Opens browser. For using script as $BROWSER.
[ -z "$1" ] && {
setsid -f "$BROWSER"
exit
}
command -v tttlog >/dev/null 2>&1 && tttlog "linkhandler $1"
# mp4/mp3 uses stream-* (my stream-link) wrapper scripts, so
# it runs behind `tsp`, meaning lots of podcasts can be
# queued in the task spooler, waits till the previous video
# stops playing before to start new ones
case "$1" in
*mkv | *webm | *mp4 | *youtube.com/watch* | *youtube.com/playlist* | *youtu.be*)
# a mpv, wrapper that plays videos picture-in-picture
# set the CLIPBOARD_CONTENTS envvar, else stream-corner grabs it from my clipboard
export CLIPBOARD_CONTENTS="$1"
shift # remove url, pass any additional arguments to stream-corner
setsid -f stream-corner-480 "$@" >/dev/null 2>&1
;;
*png | *jpg | *jpe | *jpeg | *gif)
fname="$(echo "$1" | sed "s/.*\///")"
mkdir -p /tmp/linkhandler
curl -sL "$1" >"/tmp/linkhandler/${fname}" && nsxiv -a "/tmp/linkhandler/${fname}" >/dev/null 2>&1 &
;;
*mp3 | *flac | *opus | *mp3?source*)
# stream with stream-audio (wraps stream-link, like stream-corner)
export CLIPBOARD_CONTENTS="$1"
shift
setsid -f stream-audio "$@" >/dev/null 2>&1
;;
*)
if [ -f "$1" ]; then
"$TERMINAL" -e "$EDITOR" "$1"
else openurl "$1" >/dev/null 2>&1; fi
;;
esac