xdg-sanity/xdg-sanity.sh

44 lines
730 B
Bash
Raw Normal View History

2022-09-01 20:17:23 -06:00
#!/bin/sh
2022-09-03 01:35:42 -06:00
echo "Loading extensions..."
2022-09-03 01:35:42 -06:00
INPUT=$(echo $1)
for EXT in etc/xdg-sanity/extensions/*.sh
2022-09-03 01:35:42 -06:00
do
2022-09-03 01:35:42 -06:00
TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
echo "Found $TYPE extension $EXT"
if [ "$TYPE" = "replace" ]
then
INPUT=$($EXT "$INPUT")
2022-09-03 01:35:42 -06:00
echo "Modifying $INPUT..."
echo "Got $INPUT"
fi
if [ "$TYPE" = "mime" ]
2022-09-03 01:35:42 -06:00
then
MIME=$($EXT "$INPUT")
echo $MIME
2022-09-03 01:35:42 -06:00
fi
2022-09-03 01:35:42 -06:00
done
echo "Determining MIME type of $INPUT:"
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')
fi
2022-09-01 20:17:23 -06:00
echo $MIME
BROWSER=$(cat /etc/xdg-sanity/xdg-sanity.conf | sed -ne 's/^browser = //p' )
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