Krolyxon
Commit bb5e54f

Branches

Refs →

dotfiles-x11.localbinlinkhandler

23 lines · 1.0 KB · Bourne Again Shell (bash)

1#!/bin/sh
2
3# Feed script a url or file location.
4# If an image, it will view in sxiv,
5# if a video or gif, it will view in mpv
6# if a music file or pdf, it will download,
7# otherwise it opens link in browser.
8
9# If no url given. Opens browser. For using script as $BROWSER.
10[ -z "$1" ] && { "$BROWSER"; exit; }
11
12case "$1" in
13 *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*)
14 setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;;
15 *png|*jpg|*jpe|*jpeg|*gif)
16 curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
17 *pdf|*cbz|*cbr)
18 curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
19 *mp3|*flac|*opus|*mp3?source*)
20 qndl "$1" 'curl -LO' >/dev/null 2>&1 ;;
21 *)
22 [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" >/dev/null 2>&1 || setsid -f "$BROWSER" "$1" >/dev/null 2>&1
23esac