2022-07-13 00:01:08 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# get configuration & data directories
|
|
|
|
DATA="$HOME/.cache/trss"
|
|
|
|
CONFIG="$HOME/.config/trss"
|
2022-07-17 01:10:27 -05:00
|
|
|
MODE=""
|
2022-07-13 00:01:08 -05:00
|
|
|
|
|
|
|
# make sure these directories are in place
|
|
|
|
mkdir -p "$DATA"
|
|
|
|
mkdir -p "$CONFIG"
|
|
|
|
|
|
|
|
import_information () {
|
|
|
|
FEEDS=""
|
|
|
|
for i in "$CONFIG"/*; do
|
|
|
|
. "$i"
|
|
|
|
[ -z "$FEEDS" ] && FEEDS="$NAME" || FEEDS="$FEEDS $NAME"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-07-17 08:47:30 -05:00
|
|
|
sync_individual () {
|
|
|
|
url="$(get_feed_attr "$1" feed)"
|
|
|
|
printf "> synchronizing feed %s via url %s\n" "$1" "$url"
|
|
|
|
curl "$url" -so "$DATA/${1}.xml"
|
|
|
|
|
|
|
|
# generate sfeed formatted file
|
2022-07-18 22:38:47 -05:00
|
|
|
printf "> creating sfeed compound feed file for feed %s\n" "$1"
|
2022-07-19 14:46:42 -05:00
|
|
|
cat "$DATA/${1}.xml" |
|
|
|
|
sfeed |
|
|
|
|
cat - "$DATA/${1}.sfeed" |
|
|
|
|
sort -u |
|
|
|
|
sort -r -k 1 >> "$DATA/${1}.tmp.sfeed"
|
2022-07-17 08:47:30 -05:00
|
|
|
mv "$DATA/${1}.tmp.sfeed" "${DATA}/${1}.sfeed"
|
|
|
|
}
|
|
|
|
|
2022-07-13 00:01:08 -05:00
|
|
|
synchronize () {
|
|
|
|
for i in $FEEDS; do
|
2022-07-17 08:47:30 -05:00
|
|
|
sync_individual "$i"
|
2022-07-13 00:01:08 -05:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_feed_attr () {
|
|
|
|
eval "printf '%s' \${$1_$2}"
|
|
|
|
}
|
|
|
|
|
2022-07-17 01:10:27 -05:00
|
|
|
cli_loop () {
|
|
|
|
read -p "$MODE\$ " input
|
|
|
|
case "$input" in
|
|
|
|
"ls"*)
|
|
|
|
ls_handler $input
|
|
|
|
;;
|
|
|
|
"cd"*)
|
|
|
|
cd_handler $input
|
|
|
|
;;
|
|
|
|
"cat"*)
|
|
|
|
cat_handler $input
|
|
|
|
;;
|
|
|
|
"sync"*)
|
|
|
|
sync_handler $input
|
|
|
|
;;
|
2022-07-18 22:38:47 -05:00
|
|
|
"open"*)
|
|
|
|
open_handler $input
|
2022-07-17 01:10:27 -05:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
ls_handler () {
|
|
|
|
if [ -z "$MODE" ]; then
|
|
|
|
# just list all the feeds
|
|
|
|
for i in $FEEDS; do
|
|
|
|
printf "%s\n" "$i"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# we have to list all the items in the feed
|
|
|
|
# check first if feed is downloaded
|
|
|
|
if [ -f "$DATA/${MODE}.sfeed" ]; then
|
|
|
|
awk -F'\t' '{ print $2 }' "$DATA/${MODE}.sfeed"
|
|
|
|
else
|
|
|
|
printf "synchronization of feed %s required\n" "$MODE"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cd_handler () {
|
|
|
|
if [ -z "$MODE" ]; then
|
|
|
|
# we're in the home state
|
|
|
|
[ -z "$2" ] && return
|
|
|
|
[ "$2" = ".." ] && return
|
|
|
|
|
|
|
|
# check if $2 is a valid feed
|
|
|
|
j=0
|
|
|
|
for i in $FEEDS; do
|
|
|
|
[ "$2" = "$i" ] && j=1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$j" -ne 1 ]; then
|
|
|
|
printf "trss: couldn't find feed %s\n" "$2"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set the $MODE to the feed
|
|
|
|
MODE="$2"
|
|
|
|
else
|
|
|
|
# we're in an individual feed
|
|
|
|
[ -z "$2" ] && MODE="" && return
|
|
|
|
[ "$2" = ".." ] && MODE="" && return
|
|
|
|
|
|
|
|
printf "trss: couldn't find feed %s\n" "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
sync_handler () {
|
2022-07-17 08:47:30 -05:00
|
|
|
force=0
|
|
|
|
[ "$2" = "-f" ] && force=1
|
|
|
|
[ "$3" = "-f" ] && force=1
|
|
|
|
|
|
|
|
if [ -z "$MODE" ]; then
|
|
|
|
# sync everything
|
|
|
|
synchronize
|
|
|
|
else
|
|
|
|
[ -n "$2" ] && [ ! "$2" = "-f" ] &&
|
|
|
|
sync_individual "$2" ||
|
|
|
|
sync_individual "$MODE"
|
|
|
|
fi
|
2022-07-17 01:10:27 -05:00
|
|
|
}
|
|
|
|
|
2022-07-18 22:38:47 -05:00
|
|
|
open_handler() {
|
2022-07-19 14:46:42 -05:00
|
|
|
realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^open //g')"
|
2022-07-18 22:38:47 -05:00
|
|
|
[ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs"
|
|
|
|
results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")"
|
|
|
|
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
|
|
|
|
for i in $results; do
|
2022-07-19 14:46:42 -05:00
|
|
|
url="$(printf "%s" "$i" | awk -F'\t' '{ print $3 }')"
|
2022-07-18 22:38:47 -05:00
|
|
|
|
|
|
|
echo "$url"
|
|
|
|
|
|
|
|
fire "$url" &
|
|
|
|
done
|
|
|
|
IFS="$OLDIFS"
|
2022-07-17 01:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cat_handler () {
|
|
|
|
realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^cat //g;s/ $//g')"
|
|
|
|
[ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs"
|
|
|
|
results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")"
|
|
|
|
|
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
|
|
|
|
for i in $results; do
|
|
|
|
entry="$(printf "%s" "$i" | awk -F'\t' '{ print $4 }')"
|
|
|
|
|
|
|
|
printf "%s\n" "$entry" |
|
|
|
|
sed -e 's|\\n|\n|g' -e 's|\\t|\t|g' |
|
|
|
|
lynx -stdin
|
|
|
|
done
|
2022-07-18 22:38:47 -05:00
|
|
|
IFS="$OLDIFS"
|
2022-07-17 01:10:27 -05:00
|
|
|
}
|
|
|
|
|
2022-07-13 00:01:08 -05:00
|
|
|
import_information
|
2022-07-17 01:10:27 -05:00
|
|
|
while true; do
|
|
|
|
cli_loop
|
|
|
|
done
|