~strahinja/dotfiles

dotfiles/bin/pagecheck -rwxr-xr-x 1.2 KiB
9d4b2339Страхиња Радић bin/wttrcheck: New file; .vimrc, nvim/init.vim: Added automatic setting of .pas and .slw modes 3 days ago
                                                                                
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

CACHEDIR=$HOME/.cache/pagecheck
CACHEFILE=$CACHEDIR/pagecheck.cache
PROG=$(basename $0)
NEWFILE=$CACHEDIR/pagecheck.new
WRAPWIDTH=80

function print_new()
{
	sed -e"s/\\\\e/\x1b/g" <<EOT
================================================================================
\e[1mModified: $(stat -c %y $NEWFILE)\e[0m
================================================================================

$(cat $NEWFILE)

================================================================================
EOT
}

case "$1" in
	-s|--seen)
		rm $NEWFILE 2>/dev/null
		exit 1
		;;

	-h|--help)
		echo "Usage: $PROG [[-h|--help] | [-s|--seen] | [regexp] [url] [email]]"
		exit 1
		;;
esac

if [ $# -lt 2 ]; then
	if [ -f "$NEWFILE" ]; then
		print_new
	else
		echo "$PROG: Nothing new"
	fi
	exit 0
fi

TMPFILE=$(mktemp --tmpdir -q pagecheck.XXXXX)
REGEXP=$1
URL=$2
EMAIL=$3

mkdir -p $CACHEDIR
touch $CACHEFILE
curl -s $URL | grep $REGEXP | sed -e's/<p>/\\n\\n/g' | \
	sed -e's/<[^>]\+>//g' -e's/\s\+/ /g' -e's/^\s\+//g' > $TMPFILE
if grep -v -f $CACHEFILE $TMPFILE &>/dev/null; then
	cat $TMPFILE | sed -e's/\\n\\n/\n\n/g' | sed "s/.\\{$WRAPWIDTH\\}/&\\n/g" > $NEWFILE
	print_new | neomutt -s "[$PROG] New update" $EMAIL
	print_new
	cat $TMPFILE >> $CACHEFILE
fi

rm $TMPFILE