Compare commits
3 Commits
72b169826c
...
3d168d4f9e
Author | SHA1 | Date | |
---|---|---|---|
3d168d4f9e | |||
d8f2ad2361 | |||
66fd0886a7 |
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
PREFIX = ~/.local
|
PREFIX = ~/.local
|
||||||
VERSION = 0.3.1
|
VERSION = 0.4.0
|
||||||
|
|
||||||
PKG_CONFIG = pkg-config
|
PKG_CONFIG = pkg-config
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ sub_help() {
|
|||||||
echo " fzf show articles using fzf"
|
echo " fzf show articles using fzf"
|
||||||
echo " use the commands /read (enter), /purge (ctrl-d), /purge-all (ctrl-alt-d),"
|
echo " use the commands /read (enter), /purge (ctrl-d), /purge-all (ctrl-alt-d),"
|
||||||
echo " /watch-later (ctrl-w) and /queue (ctrl-e)"
|
echo " /watch-later (ctrl-w) and /queue (ctrl-e)"
|
||||||
|
echo " you can also run 'fzf feed' for a specific feed."
|
||||||
|
echo " 'fzf -s' shuffles the feed."
|
||||||
echo
|
echo
|
||||||
echo "article commands (pass files as arguments):"
|
echo "article commands (pass files as arguments):"
|
||||||
echo " read opens link from an article file in either a browser or mpv"
|
echo " read opens link from an article file in either a browser or mpv"
|
||||||
@ -63,14 +65,19 @@ list_purge() {
|
|||||||
while read -r ARTICLE; do
|
while read -r ARTICLE; do
|
||||||
if [ -h "$ARTICLE" ]; then
|
if [ -h "$ARTICLE" ]; then
|
||||||
rm "$ARTICLE"
|
rm "$ARTICLE"
|
||||||
|
if [ -n "$INDXFILE" ]; then
|
||||||
|
ENTRY="$(grep "^[0-9]*: $ARTICLE" "$INDXFILE")"
|
||||||
|
ID="$(printf "%s" "$ENTRY" | grep -o "^[0-9]*")"
|
||||||
|
sed -i "/^$ID:.*$/d" "$LISTFILE"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_purge() {
|
sub_purge() {
|
||||||
if [ -z "$@" ]; then
|
if [ -z "$@" ]; then
|
||||||
cd "$MRSS_DIR"
|
cd "$MRSS_DIR"/new
|
||||||
rm -r "$MRSS_NEWDIR"/*
|
find . -type l -or -type f | list_purge
|
||||||
else
|
else
|
||||||
for art in "$@"; do
|
for art in "$@"; do
|
||||||
printf "%s\n" "$art"
|
printf "%s\n" "$art"
|
||||||
@ -122,7 +129,7 @@ list_read() {
|
|||||||
VIDFILES="$art"
|
VIDFILES="$art"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
xdg-open $LINK 2> /dev/null &
|
xdg-open "$LINK" 2> /dev/null &
|
||||||
sub_purge "$art"
|
sub_purge "$art"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -151,7 +158,11 @@ sub_preview() {
|
|||||||
|
|
||||||
ARTICLE="$1"
|
ARTICLE="$1"
|
||||||
|
|
||||||
DIRNAME="$(basename $(dirname "$ARTICLE"))"
|
DIRNAME="$(cat "$ARTICLE" | jq -r '.feedname // ""')"
|
||||||
|
if [ -z "$DIRNAME" ]; then
|
||||||
|
DIRNAME="$(basename $(dirname "$ARTICLE"))"
|
||||||
|
fi
|
||||||
|
|
||||||
TITLE="$(cat "$ARTICLE" | jq -r '.title')"
|
TITLE="$(cat "$ARTICLE" | jq -r '.title')"
|
||||||
DESC_TRUNC="$(cat "$ARTICLE" | jq -r '.description // ""' | w3m -dump -T text/html | head -n 20)"
|
DESC_TRUNC="$(cat "$ARTICLE" | jq -r '.description // ""' | w3m -dump -T text/html | head -n 20)"
|
||||||
|
|
||||||
@ -233,7 +244,29 @@ sub_select() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_fzf_filename() {
|
||||||
|
# searches entry in index and returns its filename
|
||||||
|
while read -r ENTRY; do
|
||||||
|
ID="$(printf "%s" "$ENTRY" | grep -o "^[0-9]*")"
|
||||||
|
grep "^$ID: " "$INDXFILE" | sed "s/^[0-9]*: //"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_fzf_preview() {
|
||||||
|
# wrapper over sub_preview() that runs fzf_filename
|
||||||
|
INDXFILE="$1"
|
||||||
|
ENTRY="$2"
|
||||||
|
sub_preview "$(echo "$ENTRY" | list_fzf_filename "$INDXFILE")"
|
||||||
|
}
|
||||||
|
|
||||||
sub_fzf() {
|
sub_fzf() {
|
||||||
|
while getopts ":s" flag; do
|
||||||
|
case "$flag" in
|
||||||
|
s) MRSS_SHUF="yes";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift `expr $OPTIND - 1`
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
DIR="$MRSS_NEWDIR"
|
DIR="$MRSS_NEWDIR"
|
||||||
else
|
else
|
||||||
@ -241,12 +274,25 @@ sub_fzf() {
|
|||||||
fi
|
fi
|
||||||
cd "$DIR"
|
cd "$DIR"
|
||||||
|
|
||||||
|
LISTFILE=`mktemp --suffix=mrss`
|
||||||
|
INDXFILE=`mktemp --suffix=mrss`
|
||||||
|
|
||||||
|
COUNTER="1"
|
||||||
|
find . -type l -or -type f \
|
||||||
|
| ([ -n "$MRSS_SHUF" ] && shuf || cat) \
|
||||||
|
| nl -ba -d'' -n'rz' -s': ' -w1 \
|
||||||
|
> "$INDXFILE"
|
||||||
|
|
||||||
|
cat "$INDXFILE" | sed "s/^[0-9]*: //" \
|
||||||
|
| xargs -rd "\n" cat \
|
||||||
|
| jq -r '[.feedname?, .title] | map(select(. != null)) | join(" - ")' \
|
||||||
|
| nl -ba -d'' -n'rz' -s': ' -w1 \
|
||||||
|
> "$LISTFILE"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
NEWARTS="$(find . -type l -or -type f)"
|
OUTPUT="$(cat "$LISTFILE" |
|
||||||
OUTPUT="$(printf "%s" "$NEWARTS" |
|
|
||||||
export SHELL="/bin/sh"
|
|
||||||
fzf --marker='*' --multi --print-query \
|
fzf --marker='*' --multi --print-query \
|
||||||
--preview "cd $DIR; mrss preview {}" \
|
--preview "cd $DIR; mrss fzf_preview '$INDXFILE' {}" \
|
||||||
--bind "ctrl-d:change-query(/purge)+accept" \
|
--bind "ctrl-d:change-query(/purge)+accept" \
|
||||||
--bind "ctrl-alt-d:change-query(/purge-all)+accept" \
|
--bind "ctrl-alt-d:change-query(/purge-all)+accept" \
|
||||||
--bind "enter:change-query(/read)+accept" \
|
--bind "enter:change-query(/read)+accept" \
|
||||||
@ -260,7 +306,7 @@ sub_fzf() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SEL="$(printf "%s" "$OUTPUT" | tail -n+2)"
|
SEL="$(printf "$OUTPUT\n" | tail -n+2 | list_fzf_filename)"
|
||||||
ACTION="$(printf "%s" "$OUTPUT" | head -n 1 | tail -c+2)"
|
ACTION="$(printf "%s" "$OUTPUT" | head -n 1 | tail -c+2)"
|
||||||
|
|
||||||
case "$ACTION" in
|
case "$ACTION" in
|
||||||
@ -291,6 +337,9 @@ sub_fzf() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
rm "$LISTFILE"
|
||||||
|
rm "$INDXFILE"
|
||||||
|
|
||||||
if [ -n "$QUEUE" ]; then
|
if [ -n "$QUEUE" ]; then
|
||||||
printf "%s\n" "$QUEUE" | list_read
|
printf "%s\n" "$QUEUE" | list_read
|
||||||
fi
|
fi
|
||||||
|
14
handlers.c
14
handlers.c
@ -155,10 +155,13 @@ openFile(const char *folder, char *fileName, char *fileExt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
outputHtml(itemStruct *item, FILE *f)
|
outputHtml(itemStruct *item, FILE *f, const char *folder)
|
||||||
{
|
{
|
||||||
if (item->fields[FIELD_TITLE])
|
if (item->fields[FIELD_TITLE])
|
||||||
fprintf(f, "<h1>%s</h1><br>\n", item->fields[FIELD_TITLE]);
|
fprintf(f, "<h1>%s</h1><br>\n", item->fields[FIELD_TITLE]);
|
||||||
|
|
||||||
|
fprintf(f, "From feed <b>%s</b><br>\n", folder);
|
||||||
|
|
||||||
if (item->fields[FIELD_LINK])
|
if (item->fields[FIELD_LINK])
|
||||||
fprintf(f, "<a href=\"%s\">Link</a><br>\n", item->fields[FIELD_LINK]);
|
fprintf(f, "<a href=\"%s\">Link</a><br>\n", item->fields[FIELD_LINK]);
|
||||||
if (item->fields[FIELD_ENCLOSURE_URL])
|
if (item->fields[FIELD_ENCLOSURE_URL])
|
||||||
@ -171,10 +174,13 @@ outputHtml(itemStruct *item, FILE *f)
|
|||||||
|
|
||||||
#ifdef JSON
|
#ifdef JSON
|
||||||
static void
|
static void
|
||||||
outputJson(itemStruct *item, FILE *f)
|
outputJson(itemStruct *item, FILE *f, const char *folder)
|
||||||
{
|
{
|
||||||
json_object *root = json_object_new_object();
|
json_object *root = json_object_new_object();
|
||||||
|
|
||||||
|
json_object_object_add(root, "feedname",
|
||||||
|
json_object_new_string(folder));
|
||||||
|
|
||||||
if (item->fields[FIELD_TITLE])
|
if (item->fields[FIELD_TITLE])
|
||||||
json_object_object_add(root, "title",
|
json_object_object_add(root, "title",
|
||||||
json_object_new_string(item->fields[FIELD_TITLE]));
|
json_object_new_string(item->fields[FIELD_TITLE]));
|
||||||
@ -211,7 +217,7 @@ processItem(itemStruct *item, const char *folder)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
char fileExt[10];
|
char fileExt[10];
|
||||||
void (*outputFunction)(itemStruct *, FILE *);
|
void (*outputFunction)(itemStruct *, FILE *, const char *);
|
||||||
|
|
||||||
switch (outputFormat) {
|
switch (outputFormat) {
|
||||||
case OUTPUT_HTML:
|
case OUTPUT_HTML:
|
||||||
@ -247,7 +253,7 @@ processItem(itemStruct *item, const char *folder)
|
|||||||
|
|
||||||
// Do not overwrite files
|
// Do not overwrite files
|
||||||
if (!ftell(itemFile)) {
|
if (!ftell(itemFile)) {
|
||||||
outputFunction(item, itemFile);
|
outputFunction(item, itemFile, folder);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
if (summaryFormat == SUMMARY_FILES)
|
if (summaryFormat == SUMMARY_FILES)
|
||||||
logMsg(LOG_OUTPUT, "%s%c%s%s\n", folder, fsep(), basename, fileExt);
|
logMsg(LOG_OUTPUT, "%s%c%s%s\n", folder, fsep(), basename, fileExt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user