Implement Extensions #5

Merged
emma merged 5 commits from extensions into main 2022-09-04 19:05:10 -06:00
3 changed files with 36 additions and 17 deletions
Showing only changes of commit 9a1c33d0d1 - Show all commits

View File

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

View File

@ -2,9 +2,9 @@
# EXT-TYPE=mime # 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 then
echo "text/html" echo "text/html"
else else

View File

@ -2,10 +2,9 @@
# EXT-TYPE=replace # 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 then
echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p' echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p'
else else