File: sfeed_markread

package info (click to toggle)
sfeed 2.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ansic: 5,176; sh: 275; makefile: 126; xml: 58
file content (35 lines) | stat: -rwxr-xr-x 754 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
# Mark items as read/unread: the input is the read / unread URL per line.

usage() {
	printf "usage: %s <read|unread> [urlfile]\n" "$0" >&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 [ -z "${urlfile}" ]; then
	usage
fi

case "$1" in
read)
	cat >> "${urlfile}"
	;;
unread)
	tmp="$(mktemp)" || exit 1
	trap "rm -f ${tmp}" EXIT
	[ -f "${urlfile}" ] || touch "${urlfile}" 2>/dev/null
	LC_ALL=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