| dmenu_rss.sh - dotfiles - These are my dotfiles. There are many like it, but th… | |
| git clone git://jay.scot/dotfiles | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| dmenu_rss.sh (1719B) | |
| --- | |
| 1 #!/bin/sh | |
| 2 # | |
| 3 # wrapper for sfeed with the following features | |
| 4 # | |
| 5 # - default to opening item in browser. | |
| 6 # - show only new items in feeds. | |
| 7 # - mpv to play youtube links. | |
| 8 # - caching to hide already viewed items. | |
| 9 # - filter items that you dont want to see. | |
| 10 # - option to show all feeds for searching | |
| 11 | |
| 12 # user config | |
| 13 ignore='parler\|trump\|biden' | |
| 14 feeds="${HOME}/.config/sfeed/feeds/" | |
| 15 | |
| 16 # apps | |
| 17 player=$(which mpv) | |
| 18 browser=$(which qutebrowser) | |
| 19 | |
| 20 # cache | |
| 21 cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}" | |
| 22 cache_unread="${cachedir}/sfeed_unread" | |
| 23 cache_read="${cachedir}/sfeed_read" | |
| 24 tmpfile=/tmp/sfeedtmp.$$ | |
| 25 | |
| 26 [ ! -e "$cachedir" ] && mkdir -p "$cachedir" | |
| 27 [ ! -f "$cache_read" ] && touch "$cache_read" | |
| 28 | |
| 29 contains() { | |
| 30 string="$1" | |
| 31 substring="$2" | |
| 32 if test "${string#*"$substring"}" != "$string"; then | |
| 33 return 0 | |
| 34 else | |
| 35 return 1 | |
| 36 fi | |
| 37 } | |
| 38 | |
| 39 mark_read() { | |
| 40 | |
| 41 sfeed_plain "$feeds/"* | grep '^N' | sort -r >>"$cache_unread" | |
| 42 awk '!seen[$0]++' "$cache_unread" >"$tmpfile" | |
| 43 cat "$tmpfile" >"$cache_read" | |
| 44 } | |
| 45 | |
| 46 show_new() { | |
| 47 true >"$cache_unread" | |
| 48 sfeed_plain "$feeds/"* | grep '^N' | sort -r >>"$cache_unread" | |
| 49 awk '!seen[$0]++' "$cache_unread" >"$tmpfile" | |
| 50 | |
| 51 data=$(grep -vxFf "$cache_read" "$tmpfile" | | |
| 52 grep -iv "$ignore" | dmenu -l 20 -i) | |
| 53 | |
| 54 rm "$tmpfile" | |
| 55 url=$(echo "$data" | sed -n 's@^.* \([a-zA-Z]*://\)\(.*\)$@\1\2@… | |
| 56 | |
| 57 test -n "$data" && echo "$data" >>"$cache_read" | |
| 58 show_content "$url" | |
| 59 } | |
| 60 | |
| 61 show_all() { | |
| 62 url=$(sfeed_plain "$feeds"/* | sort -r | dmenu -l 20 -i | | |
| 63 sed -n 's@^.* \([a-zA-Z]*://\)\(.*\)$@\1\2@p') | |
| 64 | |
| 65 show_content "$url" | |
| 66 } | |
| 67 | |
| 68 show_content() { | |
| 69 if contains "$1" "youtube.com"; then | |
| 70 $player "$1" || exit 1 | |
| 71 fi | |
| 72 | |
| 73 test -n "$1" && $browser "$1" | |
| 74 } | |
| 75 | |
| 76 case $1 in | |
| 77 -a) | |
| 78 show_all | |
| 79 exit | |
| 80 ;; | |
| 81 -r) | |
| 82 mark_read | |
| 83 exit | |
| 84 ;; | |
| 85 *) | |
| 86 show_new | |
| 87 exit | |
| 88 ;; | |
| 89 esac |