summaryrefslogtreecommitdiff
path: root/sfeed_markread
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2021-11-26 12:10:05 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2021-11-26 12:10:05 +0100
commit3cb7df56e0204bb8b0799a8317ef5a5f38802c7b (patch)
treee09077073cdcfc14d4202f6904935f2fa9de57bc /sfeed_markread
parent618a6561cd09f489e30ab652da1649a0d1fec1d5 (diff)
import sfeed_curses
Import sfeed_curses into sfeed. The files are based of the commit 8e151ce48b503ad0ff0e24cb1be3bc93d6fbd895
Diffstat (limited to 'sfeed_markread')
-rwxr-xr-xsfeed_markread35
1 files changed, 35 insertions, 0 deletions
diff --git a/sfeed_markread b/sfeed_markread
new file mode 100755
index 0000000..d0f80e2
--- /dev/null
+++ b/sfeed_markread
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Mark items as read/unread: the input is the read / unread URL per line.
+
+usage() {
+ echo "usage: $0 <read|unread> [urlfile]" >&2
+ echo "" >&2
+ echo "An urlfile must be specified as an argument or with the environment variable \$SFEED_URL_FILE" >&2
+ exit 1
+}
+
+urlfile="${2:-${SFEED_URL_FILE}}"
+if test -z "${urlfile}"; then
+ usage
+fi
+
+case "$1" in
+read)
+ cat >> "${urlfile}"
+ ;;
+unread)
+ tmp=$(mktemp)
+ trap "rm -f ${tmp}" EXIT
+ test -f "${urlfile}" || touch "${urlfile}" 2>/dev/null
+ LC_CTYPE=C awk -F '\t' '
+ { FILENR += (FNR == 1) }
+ FILENR == 1 { urls[$0] = 1 }
+ FILENR == 2 { if (!urls[$0]) { print $0 } }
+ END { exit(FILENR != 2) }' \
+ "-" "${urlfile}" > "${tmp}" && \
+ cp "${tmp}" "${urlfile}"
+ ;;
+*)
+ usage
+ ;;
+esac