sfeed_markread (754B)
1#!/bin/sh 2# Mark items as read/unread: the input is the read / unread URL per line. 3 4usage() { 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 11urlfile="${2:-${SFEED_URL_FILE}}" 12if [ -z "${urlfile}" ]; then 13 usage 14fi 15 16case "$1" in 17read) 18 cat >> "${urlfile}" 19 ;; 20unread) 21 tmp="$(mktemp)" || exit 1 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 ;; 35esac