config/polybar/news.sh

   1 #!/bin/bash
   2 
   3 mkdir -p ~/.cache/polybar
   4 
   5 cache=$_/news
   6 utime=$(date +%s)
   7 mtime=$(stat -c %Y $cache)
   8 diff=$(($utime - ${mtime:-0}))
   9 
  10 if (( $diff > $1 )) && [[ ! $(pgrep -x newsbeuter) ]]; then
  11     echo '?' > $cache
  12     newsbeuter -x reload > /dev/null
  13     n=$(newsbeuter -x print-unread | awk '{ n += $1 } END { print n }')
  14     echo $n > $cache
  15 fi
  16 
  17 cat $cache
  18