#!/bin/sh export log=/var/log/access_xdg.log # if you dont want logging either change the log function or set that var to /dev/null # might complain if this is not writable, in that case touch and chown the file grep="egrep" installed() { command -v $1 > /dev/null return $? } log() { echo "xdg: $1" echo "$1" >> $log } matches() { echo $string | "$grep" $1 > /dev/null return $? } choose() { # this check here so i can call choose with only the programm as arg if test -z $2 ; then "$1" $string > /dev/null & else "$@" > /dev/null & fi log "handle $1" exit 0 } attempt() { if installed $1 ; then choose $1 fi return 1 } if installed rg ; then grep="rg" fi export string="$1" log "recieve $string" if matches "^http://" ; then log "redirect http:// > https://" string=${string#???????} string="https://$string" fi if matches "^/" ; then log "redirect / > file://" export string="file://$1" fi if matches "^file:///." ; then if installed feh && feh -U $string ; then choose feh else if installed alacritty && installed less ; then #i came across a linux distro that didn't ship less by default, can you believe that? choose alacritty -e "less" "${string#???????}" fi fi fi if matches "^https://matrix.to/" ; then log "handle via matrix-handeler (nothing)" exit 10 fi if matches "https://" ; then # fixme, should probably fetch the ressource first and then do the tests and use the local file.. # though that might fataly confuse browsers since it is now a local ressourc if installed feh && feh -U $string ; then choose feh elif installed mpv && installed youtube-dl && youtube-dl -s $string > /dev/null ; then choose mpv --volume=70 --no-terminal $string else attempt chrome attempt chromium attempt netsurf attempt firefox fi fi if installed steam && matches "^steam://"; then choose steam fi log "handle via nothing (no handler found)" exit 255