mrss.sh: use keybinds for mrss fzf
This commit is contained in:
parent
12cb080141
commit
8fc7cb778d
@ -27,7 +27,8 @@ sub_help() {
|
|||||||
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 show articles using fzf"
|
echo " fzf show articles using fzf"
|
||||||
echo " same usage as 'select'"
|
echo " use the commands /read (enter), /purge (ctrl-d), /purge-all (ctrl-alt-d),"
|
||||||
|
echo " /watch-later (ctrl-w) and /queue (ctrl-e)"
|
||||||
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"
|
||||||
@ -134,20 +135,6 @@ list_read() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
list_watchlater() {
|
|
||||||
while read -r ARTICLE; do
|
|
||||||
REALPATH="$(realpath "$ARTICLE")"
|
|
||||||
sub_purge "$ARTICLE"
|
|
||||||
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
|
||||||
printf "%s\n" "$art"
|
printf "%s\n" "$art"
|
||||||
@ -170,6 +157,20 @@ sub_preview() {
|
|||||||
printf "\n%s\n" "$DESC_TRUNC"
|
printf "\n%s\n" "$DESC_TRUNC"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_watchlater() {
|
||||||
|
while read -r ARTICLE; do
|
||||||
|
REALPATH="$(realpath "$ARTICLE")"
|
||||||
|
sub_purge "$ARTICLE"
|
||||||
|
ln -sr "$REALPATH" "$MRSS_WATCH_LATER"/
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_watchlater() {
|
||||||
|
for art in "$@"; do
|
||||||
|
printf "%s\n" "$art"
|
||||||
|
done | list_watchlater
|
||||||
|
}
|
||||||
|
|
||||||
sub_select() {
|
sub_select() {
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
DIR="$MRSS_NEWDIR"
|
DIR="$MRSS_NEWDIR"
|
||||||
@ -235,26 +236,60 @@ sub_fzf() {
|
|||||||
DIR="$MRSS_DIR/$1"
|
DIR="$MRSS_DIR/$1"
|
||||||
fi
|
fi
|
||||||
cd "$DIR"
|
cd "$DIR"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
NEWARTS="$(find . -type l -or -type f)"
|
NEWARTS="$(find . -type l -or -type f)"
|
||||||
export -f sub_preview
|
export -f sub_preview
|
||||||
SEL="$(printf "%s" "$NEWARTS" | fzf --marker='*' --multi --cycle --preview 'bash -c "sub_preview {}"')"
|
OUTPUT="$(printf "%s" "$NEWARTS" |
|
||||||
if [ -z "$SEL" ]; then
|
fzf --marker='*' --multi --print-query \
|
||||||
|
--preview 'bash -c "sub_preview {}"' \
|
||||||
|
--bind "ctrl-d:change-query(/purge)+accept" \
|
||||||
|
--bind "ctrl-alt-d:change-query(/purge-all)+accept" \
|
||||||
|
--bind "enter:change-query(/read)+accept" \
|
||||||
|
--bind "ctrl-w:change-query(/watch-later)+accept" \
|
||||||
|
--bind "ctrl-e:change-query(/queue)+accept"
|
||||||
|
)" || break
|
||||||
|
# the break above is necessary with set -e
|
||||||
|
# otherwise bash just exits
|
||||||
|
|
||||||
|
if [ -z "$OUTPUT" ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
clear
|
|
||||||
printf "\nselected %s article(s)\n" "$(printf "%s\n" "$SEL" | wc -l)"
|
SEL="$(printf "%s" "$OUTPUT" | tail -n+2)"
|
||||||
printf "\nq quit, r read, d purge (mark read), D purge all, w watch later\n"
|
ACTION="$(printf "%s" "$OUTPUT" | head -n 1 | tail -c+2)"
|
||||||
printf "\n> "
|
|
||||||
read -n 1 ans </dev/tty
|
case "$ACTION" in
|
||||||
case "$ans" in
|
read ) printf '%s\n' "$SEL" | list_read;;
|
||||||
q ) exit;;
|
purge-all ) sub_purge; break;;
|
||||||
r ) printf '%s\n' "$SEL" | list_read;;
|
purge ) printf '%s\n' "$SEL" | list_purge;;
|
||||||
D ) sub_purge; break;;
|
watch-later ) printf '%s\n' "$SEL" | list_watchlater;;
|
||||||
d ) printf '%s\n' "$SEL" | list_purge;;
|
queue )
|
||||||
w ) printf '%s\n' "$SEL" | list_watchlater;;
|
# setting queue like this because piping to a while loop
|
||||||
|
# will make a subshell and a subshell can't modify
|
||||||
|
# variables in the parent
|
||||||
|
QUEUE="$(printf "%s\n" "$SEL" | \
|
||||||
|
# another subshell so printf shares QUEUE with the while
|
||||||
|
(
|
||||||
|
while read -r ARTICLE; do
|
||||||
|
REALPATH="$(realpath "$ARTICLE")"
|
||||||
|
if [ -n "$QUEUE" ]; then
|
||||||
|
QUEUE=$(printf "%s\n%s" "$QUEUE" "$REALPATH")
|
||||||
|
else
|
||||||
|
QUEUE="$REALPATH"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf "%s" "$QUEUE"
|
||||||
|
)
|
||||||
|
)"
|
||||||
|
printf '%s\n' "$SEL" | list_purge
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -n "$QUEUE" ]; then
|
||||||
|
printf "%s\n" "$QUEUE" | list_read
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case $subcmd in
|
case $subcmd in
|
||||||
|
Loading…
Reference in New Issue
Block a user