From 8fc7cb778dc257b1c14248eb0aa2b34b8f5b59a2 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 2 Apr 2023 10:04:43 -0400 Subject: [PATCH] mrss.sh: use keybinds for mrss fzf --- contrib/mrss.sh | 91 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/contrib/mrss.sh b/contrib/mrss.sh index 4f27003..d84477f 100755 --- a/contrib/mrss.sh +++ b/contrib/mrss.sh @@ -27,7 +27,8 @@ sub_help() { echo " you can run 'select new/feed' for a specific feed" echo " or 'select watch-later'." 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 "article commands (pass files as arguments):" echo " read opens link from an article file in either a browser or mpv" @@ -134,20 +135,6 @@ list_read() { 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() { for art in "$@"; do printf "%s\n" "$art" @@ -170,6 +157,20 @@ sub_preview() { 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() { if [ -z "$1" ]; then DIR="$MRSS_NEWDIR" @@ -235,26 +236,60 @@ sub_fzf() { DIR="$MRSS_DIR/$1" fi cd "$DIR" + while true; do NEWARTS="$(find . -type l -or -type f)" export -f sub_preview - SEL="$(printf "%s" "$NEWARTS" | fzf --marker='*' --multi --cycle --preview 'bash -c "sub_preview {}"')" - if [ -z "$SEL" ]; then + OUTPUT="$(printf "%s" "$NEWARTS" | + 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 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