1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/sh --
- set -ue
- : "${1:?}"
- : "${EDITOR:=vim}"
- : "${TERMINAL:=st}"
- : "${TERMINAL_BROWSER:=w3m}"
- # if run from terminal ($WINDOWID setted in st)
- if [ "${WINDOWID:-}" ] || [ "${LINKHANDLER_TERMINAL:-}" ]; then
- alias sw='exec swallow'
- terminal=1
- else
- alias sw='exec setsid -f --'
- terminal=0
- fi
- case "${1%%\?*}" in
- *.mkv|*.webm|*.mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*)
- sw mpv --loop-playlist=inf --quiet -- "${1}"
- ;;
- *.png|*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.gif|*.webp)
- umask 0077
- tmpd="$(mktemp -td "${0##*/}.img.XXXXXXXXX")"
- fname="$(
- fname="${1%%\?*}"
- mktemp -p "${tmpd}" "XXXXXXXXX.${fname##*.}"
- )"
- fname="${fname##*/}"
- trap 'rm -rf -- "${tmpd}"' EXIT QUIT HUP INT TERM
- curl --output-dir "${tmpd}" -sLo "${fname}" -- "${1}" && (
- cd "${tmpd}" && sw sxiv -a -- "${fname}"
- )
- ;;
- *mp3|*flac|*opus)
- sw mpv --loop-playlist=inf --no-audio-display -- "${1}"
- ;;
- https://telegra.ph/*|http://vk.com/@*)
- exec torsocks w3m "${1}"
- ;;
- *)
- if [ "${TO_CLIP:-}" ]; then
- printf %s "${1}" | xclip -selection clipboard
- elif [ -f "${1}" ]; then
- [ "${terminal}" -eq 1 ] && exec "${EDITOR}" -- "${1}"
- exec "${TERMINAL}" -e "${EDITOR}" -- "${1}"
- else
- [ "${terminal}" -eq 1 ] && exec "${TERMINAL_BROWSER}" "${1}"
- exec "${TERMINAL}" -e "${TERMINAL_BROWSER}" "${1}"
- fi
- ;;
- esac
|