links.sh (1782B)
1 #!/bin/sh 2 # 3 # links 4 # very similar to open.sh 5 # TODO: integrate this script with open.sh if i can get tee figured out 6 7 # from Objective-C regexp given on urlregex.com 8 URL_REGEXP="(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+" 9 10 main() { 11 match="$(printf '%s\n' "${@}" | grep -E "${URL_REGEXP}")" 12 13 #shellcheck disable=SC2198 14 if [ "${@}" = "${match}" ]; then 15 case "${@}" in 16 # audio 17 *.flac \ 18 | *.m4a \ 19 | *.mp3 \ 20 | *.ogg \ 21 | *.opus \ 22 | *.wav) 23 mpv --no-video "${@}" 24 ;; 25 26 # gif 27 *.gif) 28 mpv --loop "${@}" 29 ;; 30 31 # img 32 *.bmp \ 33 | *.dib \ 34 | *.ff \ 35 | *.ico \ 36 | *.iff \ 37 | *.jfi \ 38 | *.jfif \ 39 | *.jif \ 40 | *.jpe \ 41 | *.jpeg \ 42 | *.jpg \ 43 | *.lbm \ 44 | *.png \ 45 | *.pnm \ 46 | *.tga \ 47 | *.tif \ 48 | *.tiff \ 49 | *.webp \ 50 | *.xpm) 51 "${IMG_VIEWER}" "${@}" 52 ;; 53 54 # vid 55 *.avi \ 56 | *.mkv \ 57 | *.mp4 \ 58 | *.webm \ 59 | *youtube.com* \ 60 | *youtu.be*) 61 mpv "${@}" 62 ;; 63 64 # torr 65 *.torrent) 66 "${HOME}/.local/bin/bar/torr.sh" -a "${@}" 67 ;; 68 69 # web/vector 70 *.htm \ 71 | *.html \ 72 | *.php \ 73 | *.svg \ 74 | *.xhtml \ 75 | *) 76 "${BROWSER}" "${@}" 77 ;; 78 esac 79 else 80 return 1 81 fi 82 } 83 84 main "${@}"