2022-09-01 20:17:23 -06:00
|
|
|
#!/bin/sh
|
2022-09-01 23:34:11 -06:00
|
|
|
|
2022-09-03 01:35:42 -06:00
|
|
|
echo "Loading extensions..."
|
2022-09-01 23:34:11 -06:00
|
|
|
|
2022-09-03 01:35:42 -06:00
|
|
|
INPUT=$(echo $1)
|
|
|
|
|
2022-09-03 02:36:09 -06:00
|
|
|
for EXT in etc/xdg-sanity/extensions/*.sh
|
2022-09-03 01:35:42 -06:00
|
|
|
do
|
2022-09-03 02:36:09 -06:00
|
|
|
|
2022-09-03 01:35:42 -06:00
|
|
|
TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
|
2022-09-03 02:36:09 -06:00
|
|
|
echo "Found $TYPE extension $EXT"
|
|
|
|
|
|
|
|
if [ "$TYPE" = "replace" ]
|
|
|
|
then
|
|
|
|
INPUT=$($EXT "$INPUT")
|
2022-09-03 01:35:42 -06:00
|
|
|
echo "Modifying $INPUT..."
|
2022-09-03 02:36:09 -06:00
|
|
|
echo "Got $INPUT"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$TYPE" = "mime" ]
|
2022-09-03 01:35:42 -06:00
|
|
|
then
|
2022-09-03 02:36:09 -06:00
|
|
|
MIME=$($EXT "$INPUT")
|
|
|
|
echo $MIME
|
2022-09-03 01:35:42 -06:00
|
|
|
fi
|
2022-09-03 02:36:09 -06:00
|
|
|
|
2022-09-03 01:35:42 -06:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Determining MIME type of $INPUT:"
|
|
|
|
|
2022-09-03 02:36:09 -06:00
|
|
|
if [ "$MIME" = "$1" ]
|
|
|
|
then
|
2022-09-03 01:35:42 -06:00
|
|
|
MIME=$(curl -I -s "$INPUT" | sed -ne 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//g' | tr -d '\r')
|
2022-09-03 02:36:09 -06:00
|
|
|
fi
|
2022-09-01 20:17:23 -06:00
|
|
|
|
2022-09-01 23:34:11 -06:00
|
|
|
echo $MIME
|
|
|
|
|
2022-09-03 02:36:09 -06:00
|
|
|
BROWSER=$(cat /etc/xdg-sanity/xdg-sanity.conf | sed -ne 's/^browser = //p' )
|
2022-09-01 23:34:11 -06:00
|
|
|
|
2022-09-01 20:17:23 -06:00
|
|
|
if [ "$MIME" = "text/html" ]
|
|
|
|
then
|
2022-09-03 01:35:42 -06:00
|
|
|
$BROWSER $INPUT
|
2022-09-01 20:17:23 -06:00
|
|
|
else
|
2022-09-03 01:35:42 -06:00
|
|
|
handlr launch "$MIME" -- "$INPUT"
|
2022-09-01 20:17:23 -06:00
|
|
|
fi
|