xdg-sanity/xdg-sanity.sh

66 lines
1.3 KiB
Bash
Raw Normal View History

2022-09-02 02:17:23 +00:00
#!/bin/sh
2022-09-03 07:35:42 +00:00
INPUT=$(echo $1)
2022-09-04 01:26:23 +00:00
echo "Loading configuration..."
CONFIG=$(cat /etc/xdg-sanity/xdg-sanity.conf)
BROWSER=$(echo $CONFIG | sed -ne 's/^browser *= *//p')
2022-09-03 07:35:42 +00:00
2022-09-04 01:26:23 +00:00
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..."
2022-09-03 09:23:49 +00:00
for EXT in /etc/xdg-sanity/extensions/*.sh
2022-09-03 07:35:42 +00:00
do
2022-09-04 01:26:23 +00:00
if [ "$EXT" = "/etc/xdg-sanity/extensions/*.sh" ]
then
echo "No extensions to load"
else
for EXT in /etc/xdg-sanity/extensions/*.sh
do
2022-09-03 07:35:42 +00:00
TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
echo "Found $TYPE extension $EXT"
if [ "$TYPE" = "replace" ]
then
2022-09-03 07:35:42 +00:00
echo "Modifying $INPUT..."
2022-09-04 01:26:23 +00:00
INPUT=$($EXT "$INPUT")
echo "Got $INPUT"
2022-09-04 01:26:23 +00:00
else
if [ "$TYPE" = "mime" ]
2022-09-03 07:35:42 +00:00
then
2022-09-04 01:26:23 +00:00
echo "Modifying MIME type..."
MIME=$($EXT "$INPUT")
2022-09-04 01:26:23 +00:00
echo "Got $MIME"
fi
2022-09-03 07:35:42 +00:00
fi
2022-09-03 07:35:42 +00:00
done
2022-09-04 01:26:23 +00:00
fi
2022-09-03 07:35:42 +00:00
2022-09-04 01:26:23 +00:00
done
2022-09-03 07:35:42 +00:00
2022-09-04 01:26:23 +00:00
if [ "$MIME" = "" ] || [ "$MIME" = "$1" ] || [ "$MIME" = "$INPUT" ]
then
2022-09-04 01:26:23 +00:00
echo "Determining MIME type of $INPUT:"
2022-09-06 01:33:31 +00:00
# Determines HTTP code, might use for something else?
# CODE=$(curl -fLIs "$INPUT" | sed -ne 's/ [[:space:]]*$//p' | sed -ne 's|^HTTP/.\+ ||p')
MIME=$(curl -fLIs "$INPUT" | sed -ne 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//p' | tail -n1 | tr -d '\r')
echo $MIME
2022-09-04 01:26:23 +00:00
fi
2022-09-02 02:17:23 +00:00
if [ "$MIME" = "text/html" ]
then
2022-09-03 07:35:42 +00:00
$BROWSER $INPUT
2022-09-04 01:26:23 +00:00
2022-09-02 02:17:23 +00:00
else
2022-09-03 07:35:42 +00:00
handlr launch "$MIME" -- "$INPUT"
2022-09-02 02:17:23 +00:00
fi