2018-10-27 20:49:56 +00:00
|
|
|
#!/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
|
2018-10-27 21:16:57 +00:00
|
|
|
grep="egrep"
|
2018-10-27 21:58:35 +00:00
|
|
|
installed() {
|
|
|
|
command -v $1 > /dev/null
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
log() {
|
2018-10-27 20:49:56 +00:00
|
|
|
echo "xdg: $1"
|
|
|
|
echo "$1" >> $log
|
|
|
|
}
|
2018-10-27 21:58:35 +00:00
|
|
|
matches() {
|
2018-10-27 21:16:57 +00:00
|
|
|
echo $string | "$grep" $1 > /dev/null
|
2018-10-27 20:49:56 +00:00
|
|
|
return $?
|
|
|
|
}
|
2018-10-27 21:58:35 +00:00
|
|
|
choose() {
|
2018-10-29 08:48:26 +00:00
|
|
|
# this check here so i can call choose with only the programm as arg
|
2018-10-27 21:58:35 +00:00
|
|
|
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
|
2018-10-27 20:49:56 +00:00
|
|
|
export string="$1"
|
2018-10-27 21:58:35 +00:00
|
|
|
log "recieve $string"
|
2018-10-27 20:49:56 +00:00
|
|
|
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
|
2018-10-27 21:58:35 +00:00
|
|
|
if installed feh && feh -U $string ; then
|
|
|
|
choose feh
|
2018-10-27 20:49:56 +00:00
|
|
|
else
|
2018-10-27 21:58:35 +00:00
|
|
|
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
|
2018-10-27 20:49:56 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if matches "^https://matrix.to/" ; then
|
|
|
|
log "handle via matrix-handeler (nothing)"
|
|
|
|
exit 10
|
|
|
|
fi
|
|
|
|
if matches "https://" ; then
|
2018-10-29 08:48:26 +00:00
|
|
|
# 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
|
2018-10-27 21:58:35 +00:00
|
|
|
choose mpv --volume=70 --no-terminal $string
|
2018-10-27 20:49:56 +00:00
|
|
|
else
|
2018-10-27 21:58:35 +00:00
|
|
|
attempt chrome
|
|
|
|
attempt chromium
|
|
|
|
attempt netsurf
|
|
|
|
attempt firefox
|
2018-10-27 20:49:56 +00:00
|
|
|
fi
|
|
|
|
fi
|
2018-10-27 21:58:35 +00:00
|
|
|
if installed steam && matches "^steam://"; then
|
|
|
|
choose steam
|
2018-10-27 20:49:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
log "handle via nothing (no handler found)"
|
|
|
|
exit 255
|