sfeed_markread (742B)
1 #!/bin/sh 2 # Mark items as read/unread: the input is the read / unread URL per line. 3 4 usage() { 5 printf "usage: %s <read|unread> [urlfile]\n" "$0" >&2 6 echo "" >&2 7 echo "An urlfile must be specified as an argument or with the environment variable \$SFEED_URL_FILE" >&2 8 exit 1 9 } 10 11 urlfile="${2:-${SFEED_URL_FILE}}" 12 if [ -z "${urlfile}" ]; then 13 usage 14 fi 15 16 case "$1" in 17 read) 18 cat >> "${urlfile}" 19 ;; 20 unread) 21 tmp=$(mktemp) 22 trap "rm -f ${tmp}" EXIT 23 [ -f "${urlfile}" ] || touch "${urlfile}" 2>/dev/null 24 LC_ALL=C awk -F '\t' ' 25 { FILENR += (FNR == 1) } 26 FILENR == 1 { urls[$0] = 1 } 27 FILENR == 2 { if (!urls[$0]) { print $0 } } 28 END { exit(FILENR != 2) }' \ 29 "-" "${urlfile}" > "${tmp}" && \ 30 cp "${tmp}" "${urlfile}" 31 ;; 32 *) 33 usage 34 ;; 35 esac