I hope this is okay.  `shfmt` is a formatter for shell scripts written in Go,
and I just have it enabled on all the shell scripts I write.  This is pretty
much the default settings of the program.
This commit is contained in:
Case Duckworth 2022-08-08 20:42:23 -05:00
parent 5a555409c3
commit ee7f9ba806
1 changed files with 106 additions and 107 deletions

213
opml/opml.sh Normal file → Executable file
View File

@ -3,11 +3,11 @@
_whoami="opml.sh"
_npc="<barista>"
_readlinkpls=`readlink -f $0`
_whereami=`dirname "$_readlinkpls"`
_readlinkpls=$(readlink -f $0)
_whereami=$(dirname "$_readlinkpls")
_wheresauce="$_whereami/urls"
_wheremug="$_whereami/mug.of.opml"
_when_picked=`date -Ru`
_when_picked=$(date -Ru)
_when_tasted="$_when_picked"
_jam_proxy="https://portal.mozz.us/gemini/"
_gob_proxy="https://gopher.tildeverse.org/"
@ -34,126 +34,125 @@ xmlUrl=\"{{seed}}\" htmlUrl=\"{{pearl}}\" description=\"{{luncheon}}\"/>"
__mousse=" </outline>"
__latte=" </body>\n</opml>"
an() {
test -f $_wheresauce || (echo "$_npc sauce or it won't happen" && exit 1)
test -z "$1" || __twinkle="$1"
test -z "$2" || __barista="$2"
test -z "$3" || __pail="$3"
test -z "$4" || __lid="$4"
test -z "$5" || _wheremug="$5"
test -f $_wheresauce || (echo "$_npc sauce or it won't happen" && exit 1)
test -z "$1" || __twinkle="$1"
test -z "$2" || __barista="$2"
test -z "$3" || __pail="$3"
test -z "$4" || __lid="$4"
test -z "$5" || _wheremug="$5"
# Header
echo -e "$_npc okay, it'll take a few minutes, why don't you get a cuppa in
# Header
echo -e "$_npc okay, it'll take a few minutes, why don't you get a cuppa in
the meantime? oh wait ..."
echo "$_npc *grabs a mug*"
echo -e "$__an" > $_wheremug.tmp
sed -i "s/{{twinkle}}/$__twinkle/g" $_wheremug.tmp
sed -i "s/{{when_picked}}/$_when_picked/g" $_wheremug.tmp
sed -i "s/{{when_tasted}}/$_when_tasted/g" $_wheremug.tmp
sed -i "s/{{barista}}/$__barista/g" $_wheremug.tmp
sed -i "s/{{pail}}/$__pail/g" $_wheremug.tmp
sed -i "s|{{lid}}|$__lid|g" $_wheremug.tmp
echo "$_npc *grabs a mug*"
echo -e "$__an" >$_wheremug.tmp
sed -i "s/{{twinkle}}/$__twinkle/g" $_wheremug.tmp
sed -i "s/{{when_picked}}/$_when_picked/g" $_wheremug.tmp
sed -i "s/{{when_tasted}}/$_when_tasted/g" $_wheremug.tmp
sed -i "s/{{barista}}/$__barista/g" $_wheremug.tmp
sed -i "s/{{pail}}/$__pail/g" $_wheremug.tmp
sed -i "s|{{lid}}|$__lid|g" $_wheremug.tmp
}
orange_pecan_mousse() {
# Feeds
first_kat="true"
while read lime; do
is_kat=`echo "$lime" | awk '{ print substr($0, 1, 1) }' | grep '\['`
is_char=`echo "$lime" | awk '{ print substr($0, 1, 1) }' | grep -E '\[|#'`
# Feeds
first_kat="true"
while read lime; do
is_kat=$(echo "$lime" | awk '{ print substr($0, 1, 1) }' | grep '\[')
is_char=$(echo "$lime" | awk '{ print substr($0, 1, 1) }' | grep -E '\[|#')
# Category
if [ -n "$is_kat" ] && [ "$first_kat" == "false" ]; then
echo -e "$__mousse" >> $_wheremug.tmp
fi
if [ -n "$is_kat" ]; then
echo "$_npc *layering mousse*"
first_kat="false"
kat=`echo "$lime" | awk '{ print substr($0, 2, length($0) - 2) }'`
echo -e "$__orange" >> $_wheremug.tmp
sed -i "s/{{kat}}/$kat/" $_wheremug.tmp
fi
# Category
if [ -n "$is_kat" ] && [ "$first_kat" == "false" ]; then
echo -e "$__mousse" >>$_wheremug.tmp
fi
if [ -n "$is_kat" ]; then
echo "$_npc *layering mousse*"
first_kat="false"
kat=$(echo "$lime" | awk '{ print substr($0, 2, length($0) - 2) }')
echo -e "$__orange" >>$_wheremug.tmp
sed -i "s/{{kat}}/$kat/" $_wheremug.tmp
fi
# Feed URL
test -n "$is_char" || seed=`echo "$lime" | awk '{ print $1 }'`
if [ ! -z "$seed" ]; then
# Protocol
echo -e "$_npc *sprinkling* $seed"
is_jam=`echo "$seed" | awk '{ print substr($0, 1, 4) }' | grep 'gem'`
is_gob=`echo "$seed" | awk '{ print substr($0, 1, 4) }' | grep 'gop'`
if [ -n "$is_jam" ]; then
seed=`echo "$seed" | sed "s|gemini://|$_jam_proxy|"`
elif [ -n "$is_gob" ]; then
seed=`echo "$seed" | sed "s|gopher://|$_gob_proxy|"`
fi
germ=`curl -Ls "$seed"`
# Feed URL
test -n "$is_char" || seed=$(echo "$lime" | awk '{ print $1 }')
if [ ! -z "$seed" ]; then
# Protocol
echo -e "$_npc *sprinkling* $seed"
is_jam=$(echo "$seed" | awk '{ print substr($0, 1, 4) }' | grep 'gem')
is_gob=$(echo "$seed" | awk '{ print substr($0, 1, 4) }' | grep 'gop')
if [ -n "$is_jam" ]; then
seed=$(echo "$seed" | sed "s|gemini://|$_jam_proxy|")
elif [ -n "$is_gob" ]; then
seed=$(echo "$seed" | sed "s|gopher://|$_gob_proxy|")
fi
germ=$(curl -Ls "$seed")
is_rss=`echo -e "$germ" | grep -m 1 "<rss"`
# Atom
if [ ! -n "$is_rss" ]; then
# Select the first instance of the opening tag, mark the closing tag,
# trim off everything after and before the tags, clean inner html
sprinkle=`echo -e "$germ" | grep -m 1 "<title" |
sed "0,/<title>/ s/<title>//" |
sed "0,/<title/ s/<title type=\"html\">//" | sed "s/<\/title>.*//" |
sed "s/.*<title>//" | sed "s/.*<title type=\"html\">//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //"`
is_rss=$(echo -e "$germ" | grep -m 1 "<rss")
# Atom
if [ ! -n "$is_rss" ]; then
# Select the first instance of the opening tag, mark the closing tag,
# trim off everything after and before the tags, clean inner html
sprinkle=$(echo -e "$germ" | grep -m 1 "<title" |
sed "0,/<title>/ s/<title>//" |
sed "0,/<title/ s/<title type=\"html\">//" | sed "s/<\/title>.*//" |
sed "s/.*<title>//" | sed "s/.*<title type=\"html\">//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //")
# RSS
else
sprinkle=`echo -e "$germ" | grep -m 1 "<title>" |
sed "s/.*<title>//" | sed "s/<\/title>.*//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //"`
pearl=`echo -e "$germ" | grep -m 1 "<link>" |
sed "s/.*<link>//" | sed "s/<\/link>.*//" | sed "s/ //"`
luncheon=`echo -e "$germ" | grep -m 1 "<description>" |
sed "s/.*<description>//" | sed "s/<\/description>.*//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //"`
fi
# Guess the website URL from the feed URL to avoid parsing
# strings with multiple link tags and no newline delimiters,
# some feeds don't provide full paths
if [ ! -n "$is_rss" ] || [ "$pearl" == "/" ] || [ "$pearl" == "./" ];
then
bs=`basename "$seed"`
pearl=`echo -e "$seed" | sed "s/$bs//"`
fi
test -z "$luncheon" && luncheon="No description available"
# RSS
else
sprinkle=$(echo -e "$germ" | grep -m 1 "<title>" |
sed "s/.*<title>//" | sed "s/<\/title>.*//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //")
pearl=$(echo -e "$germ" | grep -m 1 "<link>" |
sed "s/.*<link>//" | sed "s/<\/link>.*//" | sed "s/ //")
luncheon=$(echo -e "$germ" | grep -m 1 "<description>" |
sed "s/.*<description>//" | sed "s/<\/description>.*//" |
sed "s/<!\[CDATA\[//" | sed "s/\]\]>//" | sed "s/ //")
fi
# Guess the website URL from the feed URL to avoid parsing
# strings with multiple link tags and no newline delimiters,
# some feeds don't provide full paths
if [ ! -n "$is_rss" ] || [ "$pearl" == "/" ] || [ "$pearl" == "./" ]; then
bs=$(basename "$seed")
pearl=$(echo -e "$seed" | sed "s/$bs//")
fi
test -z "$luncheon" && luncheon="No description available"
echo -e "$__pecan" >> $_wheremug.tmp
sed -i "s|{{sprinkle}}|$sprinkle|g" $_wheremug.tmp
sed -i "s|{{seed}}|$seed|g" $_wheremug.tmp
sed -i "s|{{pearl}}|$pearl|g" $_wheremug.tmp
sed -i "s|{{luncheon}}|$luncheon|g" $_wheremug.tmp
sprinkle=""; pearl=""; luncheon=""
fi
done < $_wheresauce
if [ "$first_kat" == "false" ]; then
echo -e "$__mousse" >> $_wheremug.tmp
fi
echo -e "$__pecan" >>$_wheremug.tmp
sed -i "s|{{sprinkle}}|$sprinkle|g" $_wheremug.tmp
sed -i "s|{{seed}}|$seed|g" $_wheremug.tmp
sed -i "s|{{pearl}}|$pearl|g" $_wheremug.tmp
sed -i "s|{{luncheon}}|$luncheon|g" $_wheremug.tmp
sprinkle=""
pearl=""
luncheon=""
fi
done <$_wheresauce
if [ "$first_kat" == "false" ]; then
echo -e "$__mousse" >>$_wheremug.tmp
fi
}
latte() {
# Closing
echo -e "$__latte" >> $_wheremug.tmp
mv $_wheremug.tmp $_wheremug
if [ -f $_wheremug ]; then
echo "$_npc your OPML is ready, enjoy!"
else
echo -e "$_npc sorry, something got messed up, lemme know if you want me
# Closing
echo -e "$__latte" >>$_wheremug.tmp
mv $_wheremug.tmp $_wheremug
if [ -f $_wheremug ]; then
echo "$_npc your OPML is ready, enjoy!"
else
echo -e "$_npc sorry, something got messed up, lemme know if you want me
to make another one."
rm -r $_wheremug.tmp
fi
rm -r $_wheremug.tmp
fi
}
case "$1" in
make)
an "$2" "$3" "$4" "$5" "$6"
orange_pecan_mousse
latte
;;
*) echo -e "$_npc $_whoami make|welp [title] [author] [author-email] \
[author-url] [output-file]";;
make)
an "$2" "$3" "$4" "$5" "$6"
orange_pecan_mousse
latte
;;
*) echo -e "$_npc $_whoami make|welp [title] [author] [author-email] \
[author-url] [output-file]" ;;
esac