swaydots

my dotfiles
git clone https://git.awy.one/swaydots.git
Log | Files | Refs | README | LICENSE

linkhandler (1320B)


      1 #!/bin/sh
      2 
      3 # Feed script a url or file location.
      4 # If an image, it will view in swayimg,
      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 [ -z "$1" ]; then
     10 	url="$(wl-paste)"
     11 else
     12 	url="$1"
     13 fi
     14 
     15 # Check if the URL is from inv.nadeko.net and adjust it for YouTube
     16 echo "$url" | grep -q 'inv.nadeko.net/watch'
     17 if [ $? -eq 0 ]; then
     18 	url="https://www.youtube.com/watch?v=$(echo "$url" | sed 's/.*inv\.nadeko\.net\/watch?v=\([^&]*\)/\1/')"
     19 fi
     20 
     21 case "$url" in
     22 	*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtube.com/v/*|*youtube.com/shorts*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*)
     23 		setsid -f mpv -quiet "$url" >/dev/null 2>&1 ;;
     24 	*png|*jpg|*jpe|*jpeg|*gif|*webp)
     25 		curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && swayimg "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")"  >/dev/null 2>&1 & ;;
     26 	*pdf|*cbz|*cbr)
     27 		curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")"  >/dev/null 2>&1 & ;;
     28 	*mp3|*flac|*opus|*mp3?source*)
     29 		qndl "$url" 'curl -LO'  >/dev/null 2>&1 ;;
     30 	*)
     31 		[ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1
     32 esac