mrss.sh: 'fzf' subcommand now has actions
This commit is contained in:
parent
59c6f89662
commit
7d1c7a7a38
@ -23,13 +23,17 @@ sub_help() {
|
|||||||
echo
|
echo
|
||||||
echo "commands:"
|
echo "commands:"
|
||||||
echo " update updates feeds"
|
echo " update updates feeds"
|
||||||
echo " read opens link from an article file in either a browser or mpv"
|
|
||||||
echo " select show each new article and prompt for an action;"
|
echo " select show each new article and prompt for an action;"
|
||||||
echo " you can run 'select new/feed' for a specific feed"
|
echo " you can run 'select new/feed' for a specific feed"
|
||||||
echo " or 'select watch-later'."
|
echo " or 'select watch-later'."
|
||||||
echo " fzf select articles to read using fzf"
|
echo " fzf show articles using fzf"
|
||||||
echo " link print the article link from a .json file"
|
echo " same usage as 'select'"
|
||||||
echo " purge purge new/ directory"
|
echo
|
||||||
|
echo "article commands (pass files as arguments):"
|
||||||
|
echo " read opens link from an article file in either a browser or mpv"
|
||||||
|
echo " link print the article link"
|
||||||
|
echo " purge mark an article read, or mark all articles read (if no args passed)"
|
||||||
|
echo " watchlater move articles to a watch-later directory"
|
||||||
echo
|
echo
|
||||||
echo "The following is required to use this script:"
|
echo "The following is required to use this script:"
|
||||||
echo " - jq"
|
echo " - jq"
|
||||||
@ -54,13 +58,32 @@ sub_update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_purge() {
|
||||||
|
while read -r ARTICLE; do
|
||||||
|
if [ -h "$ARTICLE" ]; then
|
||||||
|
rm "$ARTICLE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
sub_purge() {
|
sub_purge() {
|
||||||
cd "$MRSS_DIR"
|
if [ -z "$@" ]; then
|
||||||
rm -r "$MRSS_NEWDIR"/*
|
cd "$MRSS_DIR"
|
||||||
|
rm -r "$MRSS_NEWDIR"/*
|
||||||
|
else
|
||||||
|
for art in "$@"; do
|
||||||
|
printf "%s\n" "$art"
|
||||||
|
done | list_purge
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
list_link() {
|
||||||
|
for art in "$@"; do
|
||||||
|
cat "$art" | jq -r '.enclosure.link // .link'
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_link() {
|
sub_link() {
|
||||||
# extract the link from a single article file
|
|
||||||
cat "$@" | jq -r '.enclosure.link // .link'
|
cat "$@" | jq -r '.enclosure.link // .link'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,16 +102,13 @@ list_read() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
xdg-open $LINK 2> /dev/null &
|
xdg-open $LINK 2> /dev/null &
|
||||||
if [ -h "$art" ]; then
|
sub_purge "$art"
|
||||||
# remove symlinks from new/
|
|
||||||
rm "$art"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$VID" ]; then
|
if [ -n "$VID" ]; then
|
||||||
if mpv $VID 2> /dev/null; then
|
if mpv $VID 2> /dev/null; then
|
||||||
printf "%s" "$VIDFILES" | xargs -d "\n" rm
|
printf "%s" "$VIDFILES" | list_purge
|
||||||
else
|
else
|
||||||
printf "\n%s%s%s\n" \
|
printf "\n%s%s%s\n" \
|
||||||
$blue \
|
$blue \
|
||||||
@ -98,9 +118,23 @@ list_read() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_watchlater() {
|
||||||
|
while read -r ARTICLE; do
|
||||||
|
REALPATH="$(realpath "$ARTICLE")"
|
||||||
|
sub_purge "$art"
|
||||||
|
ln -sr "$REALPATH" "$MRSS_WATCH_LATER"/
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_watchlater() {
|
||||||
|
for art in "$@"; do
|
||||||
|
printf "%s\n" "$art"
|
||||||
|
done | list_watchlater
|
||||||
|
}
|
||||||
|
|
||||||
sub_read() {
|
sub_read() {
|
||||||
for art in "$@"; do
|
for art in "$@"; do
|
||||||
echo "$art"
|
printf "%s\n" "$art"
|
||||||
done | list_read
|
done | list_read
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +176,7 @@ sub_select() {
|
|||||||
sub_preview "$ARTICLE"
|
sub_preview "$ARTICLE"
|
||||||
|
|
||||||
printf "\n\n-----------------\n"
|
printf "\n\n-----------------\n"
|
||||||
printf "\nq quit, r read, e queue article, f full summary, d mark read,\n"
|
printf "\nq quit, r read, e queue article, f full summary, d purge (mark read),\n"
|
||||||
printf "s skip, S skip all, w watch later\n"
|
printf "s skip, S skip all, w watch later\n"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
@ -162,16 +196,11 @@ sub_select() {
|
|||||||
cat "$ARTICLE" | jq -r '.description // ""' | w3m -o confirm_qq=false -T text/html
|
cat "$ARTICLE" | jq -r '.description // ""' | w3m -o confirm_qq=false -T text/html
|
||||||
;;
|
;;
|
||||||
d )
|
d )
|
||||||
if [ -h "$ARTICLE" ]; then
|
sub_purge "$ARTICLE"
|
||||||
rm "$ARTICLE"
|
|
||||||
fi
|
|
||||||
break;;
|
break;;
|
||||||
s ) break;;
|
s ) break;;
|
||||||
S ) SKIPALL="y"; break;;
|
S ) SKIPALL="y"; break;;
|
||||||
w )
|
w ) sub_watchlater "$ARTICLE"
|
||||||
REALPATH="$(realpath "$ARTICLE")"
|
|
||||||
rm "$ARTICLE"
|
|
||||||
ln -sr "$REALPATH" "$MRSS_WATCH_LATER"/
|
|
||||||
break;;
|
break;;
|
||||||
* ) break;;
|
* ) break;;
|
||||||
esac
|
esac
|
||||||
@ -190,10 +219,26 @@ sub_fzf() {
|
|||||||
DIR="$MRSS_DIR/$1"
|
DIR="$MRSS_DIR/$1"
|
||||||
fi
|
fi
|
||||||
cd "$DIR"
|
cd "$DIR"
|
||||||
NEWARTS="$(find . -type l)"
|
while true; do
|
||||||
export -f sub_preview
|
NEWARTS="$(find . -type l)"
|
||||||
printf "%s" "$NEWARTS" | fzf --disabled --marker='*' --multi --cycle --preview 'bash -c "sub_preview {}"' | \
|
export -f sub_preview
|
||||||
list_read
|
SEL="$(printf "%s" "$NEWARTS" | fzf --disabled --marker='*' --multi --cycle --preview 'bash -c "sub_preview {}"')"
|
||||||
|
if [ -z "$SEL" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
clear
|
||||||
|
printf "\nselected %s article(s)\n" "$(printf "%s\n" "$SEL" | wc -l)"
|
||||||
|
printf "\nq quit, r read, d purge (mark read), D purge all, w watch later\n"
|
||||||
|
printf "\n> "
|
||||||
|
read -n 1 ans </dev/tty
|
||||||
|
case "$ans" in
|
||||||
|
q ) exit;;
|
||||||
|
r ) printf '%s\n' "$SEL" | list_read;;
|
||||||
|
D ) sub_purge; break;;
|
||||||
|
d ) printf '%s\n' "$SEL" | list_purge;;
|
||||||
|
w ) printf '%s\n' "$SEL" | list_watchlater;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
case $subcmd in
|
case $subcmd in
|
||||||
|
Loading…
Reference in New Issue
Block a user