Feedr/feedr.sh
Schimon Jehudah, Adv. d868301262 Initial set of files.
2024-11-28 08:19:43 +02:00

62 lines
1.7 KiB
Bash

#!/bin/bash
# Check if the correct number of arguments is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 XML_FILE"
exit 1
fi
function browser() {
local URL="$1";
xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL;
}
# Get the XML file and stylesheet file from the arguments
XML_FILE="$1"
XML_FILENAME=$(basename $XML_FILE)
# Create a temporary directory
TEMPORARY_DIRECTORY="/tmp/feedr"
if [ ! -f "$TEMPORARY_DIRECTORY" ]; then
mkdir $TEMPORARY_DIRECTORY/
mkdir $TEMPORARY_DIRECTORY/css/
mkdir $TEMPORARY_DIRECTORY/xsl/
fi
# Check whether a custom stylesheet is present
STYLESHEET_DIRECTORY="$HOME/.local/share/feedr"
cp -rf "$STYLESHEET_DIRECTORY/css/" "$TEMPORARY_DIRECTORY/"
cp -rf "$STYLESHEET_DIRECTORY/xsl/" "$TEMPORARY_DIRECTORY/"
if [ ! -f "$STYLESHEET_DIRECTORY" ]; then
STYLESHEET_DIRECTORY="/usr/share/feedr"
fi
# Copy stylesheets to temporary directory
cp -rf "$STYLESHEET_DIRECTORY/css/" "$TEMPORARY_DIRECTORY/"
cp -rf "$STYLESHEET_DIRECTORY/xsl/" "$TEMPORARY_DIRECTORY/"
# Restructure file with xmllint
XML_FILE_TMP="$TEMPORARY_DIRECTORY/$XML_FILENAME.xml"
xmllint --format "$XML_FILE" > "$XML_FILE_TMP"
if ! grep -q xml-stylesheet "$XML_FILE_TMP"; then
sed -i '1a <?xml-stylesheet type="text/xsl" href="xsl/stylesheet.xsl"?>' "$XML_FILE_TMP"
# Move modified content back to the original file
#mv "$XML_FILE_TMP" "$XML_FILE"
# Print a confirmation message
echo "Stylesheet instruction added to $XML_FILE."
fi
export WEBKIT_DISABLE_DMABUF_RENDERER=1
#badwolf "$XML_FILE_TMP"
#chrome --new-window "$XML_FILE_TMP"
#falkon "$XML_FILE_TMP" --new-window
#firefox --new-window "$XML_FILE_TMP"
#luakit "$XML_FILE_TMP"
otter-browser "$XML_FILE_TMP"
qutebrowser "$XML_FILE_TMP"
#xdg-open "$XML_FILE_TMP"