~kaction/savepage

ref: af884e3e9b924fc4358e0634011824dda63258c7 savepage/savepage.exec -rwxr-xr-x 1.3 KiB View raw
af884e3e — Dmitry Bogatov Write and install manpage for "fbclear" 4 months 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
#!/usr/bin/env execlineb
importas -in SAVED_PATH PATH
##: export PATH @path@
importas -in \# \#
importas -in HOME HOME
importas -D ${HOME}/.savepage.json SAVEPAGE_FILE SAVEPAGE_FILE

ifelse { test $# = 0 } { echo "usage: savepage fbpdf [args] filename" }
ifelse { test $# = 1 } { elgetpositionals exec $@ }
importas -in filename $#
backtick -DNONE hashsum {
	redirfd -w 2 /dev/null
	pipeline -w { cut -f1 -d" " } sha256sum $filename
}
importas -in hashsum hashsum
ifelse { test $hashsum = NONE } { exec $@ }
backtick -n -D 1 page {
	redirfd -w 2 /dev/null
	jq ".[$key] // 1" --arg key $hashsum --raw-output ${SAVEPAGE_FILE}
}
importas -in page page
importas -in prog 1
shift
elgetpositionals
backtick -in tmpfile { mktemp }
importas -in tmpfile tmpfile
redirfd -w 4 $tmpfile
foreground { export PATH $SAVED_PATH exec $prog -p $page $@ }
importas -in err ?
ifthenelse { test $err = 0 } {
	ifthenelse { test -f ${SAVEPAGE_FILE} } { true } {
		redirfd -w 1 ${SAVEPAGE_FILE}
		echo "{}"
	}
	backtick -in new_page { cat $tmpfile }
	importas -in new_page new_page
	
	if {
		redirfd -w 1 ${SAVEPAGE_FILE}.tmp
		jq ".[$key] = $value"
			--arg key $hashsum
			--argjson value $new_page
			${SAVEPAGE_FILE}
	}
	if { mv ${SAVEPAGE_FILE}.tmp ${SAVEPAGE_FILE} }
} { true }
foreground { rm -f $tmpfile }
exit $err