rss.sh (1429B)
1 #!/bin/sh 2 # 3 # rss 4 5 ICON='' 6 GET_ICON='' 7 TMP='/tmp/get-rss' 8 RSS="${XDG_CACHE_HOME:-${HOME}/.cache/}/dots/bar/rss" 9 10 bar() { 11 # is reloading 12 [ -f "${TMP}" ] && cat "${TMP}" && exit 0 13 14 # a decent way of finding out if prog is open without pgrep 15 # TODO: implement this in other scripts where ps -ef is used 16 if ps -ef | grep "${RSS_READER}" | tr -s ' ' | cut -f8- -d ' ' | grep -qx "${RSS_READER}"; then 17 printf '%s\n' "${ICON}" 18 else 19 # print cache if newsboat is reloading 20 newsboat -x print-unread >/dev/null 21 [ "${?}" -eq 1 ] && printf '%s\n' "${ICON} $(grep '^[0-9][0-9]*$' "${RSS}")" && exit 0 22 23 # print unread articles 24 unread="$(newsboat -x print-unread | awk '{print $1}')" 25 printf '%s\n' "${unread}" > "${RSS}" 26 printf '%s\n' "${ICON} ${unread}" 27 fi 28 } 29 30 get_rss() { 31 printf '%s\n' "${GET_ICON}" > "${TMP}" 32 newsboat -x reload >/dev/null 33 rm -f "${TMP}" 34 } 35 36 open() { "${TERMINAL}" -c "${RSS_READER}" -e "${RSS_READER}" ; } 37 38 main() { 39 # called from bar 40 [ ${#} -eq 0 ] && bar 41 42 # bar usage 43 case ${BLOCK_BUTTON} in 44 1) open ;; 45 2) get_rss ;; 46 esac 47 48 while getopts 'go' opt; do 49 case "${opt}" in 50 # get rss if called with g flag 51 g) get_rss ;; 52 # open rss if o flag used 53 o) open ;; 54 *) return ;; 55 esac 56 done 57 } 58 59 main "${@}"