xdg-sanity/xdg-sanity.sh

44 lines
730 B
Bash
Executable File

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