complete refactor

This commit is contained in:
Emma Tebibyte 2022-09-03 21:26:23 -04:00
parent 48cc64b7ee
commit ec7ec0c885
3 changed files with 36 additions and 17 deletions

View File

@ -1,44 +1,64 @@
#!/bin/sh
echo "Loading extensions..."
INPUT=$(echo $1)
echo "Loading configuration..."
CONFIG=$(cat /etc/xdg-sanity/xdg-sanity.conf)
BROWSER=$(echo $CONFIG | sed -ne 's/^browser *= *//p')
if [ "$BROWSER" = "" ]
then
echo "Please place the path to your default browser's executable in /etc/xdg-sanity/xdg-sanity.conf"
exit
else
echo "Found default browser $BROWSER"
fi
echo "Loading extensions..."
for EXT in /etc/xdg-sanity/extensions/*.sh
do
if [ "$EXT" = "/etc/xdg-sanity/extensions/*.sh" ]
then
echo "No extensions to load"
else
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..."
INPUT=$($EXT "$INPUT")
echo "Got $INPUT"
fi
else
if [ "$TYPE" = "mime" ]
then
echo "Modifying MIME type..."
MIME=$($EXT "$INPUT")
echo $MIME
echo "Got $MIME"
fi
fi
done
fi
done
echo "Determining MIME type of $INPUT:"
if [ "$MIME" = "$1" ]
if [ "$MIME" = "" ] || [ "$MIME" = "$1" ] || [ "$MIME" = "$INPUT" ]
then
echo "Determining MIME type of $INPUT:"
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' )
fi
if [ "$MIME" = "text/html" ]
then
$BROWSER $INPUT
else
handlr launch "$MIME" -- "$INPUT"
fi

View File

@ -2,9 +2,9 @@
# EXT-TYPE=mime
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -ne 's/\/.*\+//p')
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
if [ $TEST = "teddit.net" ]
if [ "$TEST" = "teddit.net" ]
then
echo "text/html"
else

View File

@ -2,10 +2,9 @@
# EXT-TYPE=replace
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -ne 's/\/.*\+//p')
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
if [ $TEST = "youtube.com" ]
if [ "$TEST" = "youtube.com" ]
then
echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p'
else