Implement Extensions #5
@ -1,17 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Determining MIME type of $1:"
|
||||
INPUT=$(echo $1)
|
||||
echo "Loading configuration..."
|
||||
CONFIG=$(cat /etc/xdg-sanity/xdg-sanity.conf)
|
||||
BROWSER=$(echo $CONFIG | sed -ne 's/^browser *= *//p')
|
||||
|
||||
MIME=$(curl -I -s "$1" | sed -n -e 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//g' | tr -d '\r')
|
||||
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
|
||||
echo "Modifying $INPUT..."
|
||||
INPUT=$($EXT "$INPUT")
|
||||
echo "Got $INPUT"
|
||||
|
||||
else
|
||||
if [ "$TYPE" = "mime" ]
|
||||
then
|
||||
echo "Modifying MIME type..."
|
||||
MIME=$($EXT "$INPUT")
|
||||
echo "Got $MIME"
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
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')
|
||||
echo $MIME
|
||||
|
||||
BROWSER=$(cat /etc/xdg-sanity.conf | sed -n -e 's/^browser = //p' )
|
||||
fi
|
||||
|
||||
if [ "$MIME" = "text/html" ]
|
||||
then
|
||||
$BROWSER $1
|
||||
$BROWSER $INPUT
|
||||
|
||||
else
|
||||
handlr launch "$MIME" -- "$1"
|
||||
handlr launch "$MIME" -- "$INPUT"
|
||||
fi
|
12
xdg-sanity/extensions/teddit-mime.sample
Executable file
12
xdg-sanity/extensions/teddit-mime.sample
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# EXT-TYPE=mime
|
||||
|
||||
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
|
||||
|
||||
if [ "$TEST" = "teddit.net" ]
|
||||
then
|
||||
echo "text/html"
|
||||
else
|
||||
echo $1
|
||||
fi
|
12
xdg-sanity/extensions/youtube-replace.sample
Executable file
12
xdg-sanity/extensions/youtube-replace.sample
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# EXT-TYPE=replace
|
||||
|
||||
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
|
||||
|
||||
if [ "$TEST" = "youtube.com" ]
|
||||
then
|
||||
echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p'
|
||||
else
|
||||
echo $1
|
||||
fi
|
Loading…
Reference in New Issue
Block a user