Last active
April 15, 2020 03:24
-
-
Save achilleas-k/dec9143224fc94a8a3a1176390220a35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
shopt -s nocasematch # for case test | |
browser="/usr/bin/qutebrowser --target window" | |
URL=$1 | |
case "${URL}" in | |
*.jpg | *.jpeg | *.png) | |
prog="feh --scale-down" | |
icon="feh" | |
message="Opening image in feh" | |
;; | |
*youtube* | *youtu.be* | *.mp4 | *streamable* | *gfycat.com* | *tiktok.com*) | |
prog="mpv" | |
icon="mpv" | |
message="Opening video in mpv" | |
;; | |
*.gif | *.gifv) | |
prog="mpv --loop" | |
icon="mpv" | |
message="Opening gif in mpv" | |
;; | |
*.pdf | *.md) | |
prog="okular" | |
icon="okular" | |
message="Opening document in Okular" | |
;; | |
*) | |
prog=${browser} | |
icon="qutebrowser" | |
message="Opening URL in Qutebroser" | |
;; | |
esac | |
# rest of args are ignored | |
if [ -e "${URL}" ]; then | |
# file or dir; open with file://<absolute path> | |
URL=$(realpath "${URL}") | |
URL="file://${URL}" | |
fi | |
ecode=0 | |
notify-send --app-name="URL handler" --icon="${icon}" "URL handler" "${message}" | |
stderr=$(${prog} "${URL}" 2>&1) || ecode=$? | |
if [[ ${ecode} != 0 ]]; then | |
# TODO: Add icon | |
notify-send "Failed to open URL" "Command ${prog} ${URL} failed:\n${stderr}" | |
# default to browser | |
${browser} ${URL} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment