linkhandler.sh 813 B

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