aboutsummaryrefslogtreecommitdiff
path: root/bin/setbg-texample
diff options
context:
space:
mode:
authorCamil Staps2016-04-26 17:23:04 +0200
committerCamil Staps2016-11-30 19:11:42 +0100
commitade8acf834b3861318217e4e11310295199aff09 (patch)
tree07f0f9262199c059c81b125a7ab7caaa91f269db /bin/setbg-texample
parentReorganised vim (diff)
Better failing in setbg
Diffstat (limited to 'bin/setbg-texample')
-rwxr-xr-xbin/setbg-texample19
1 files changed, 15 insertions, 4 deletions
diff --git a/bin/setbg-texample b/bin/setbg-texample
index 5c06b6d..f2afcab 100755
--- a/bin/setbg-texample
+++ b/bin/setbg-texample
@@ -1,22 +1,32 @@
#!/bin/bash
-# Test internet
-wget -q --spider --timeout=2 https://google.com
-if [ $? -ne 0 ]; then exit -1; fi
-
SCR_WIDTH=1980
SCR_HEIGHT=1080
PADDING=50
FONT_SIZE=20
+function fail() {
+ if [ -f ~/.bg.png ]; then
+ feh --bg-max -B white ~/.bg.png
+ fi
+ exit -1;
+}
+
+# Test internet
+timeout 2 wget -q --spider http://texample.net
+if [ $? -ne 0 ]; then fail; fi
+
let "SCR_WIDTH -= 2 * $PADDING"
let "SCR_WIDTH /= 2"
let "SCR_HEIGHT -= 2 * $PADDING"
PAGE=$RANDOM; let "PAGE %= 22"; let "PAGE += 1"
+# Fetch list of texamples
cd /tmp
wget -qO texample.html "http://texample.net/tikz/examples/all/?page=$PAGE"
+if [ $? -ne 0 ]; then fail; fi
+
EXAMPLES="$(grep '^<dl' texample.html | wc -l)"
awk -v n=0 "BEGIN{n=int(rand()*$EXAMPLES)+1} /^<dl/{l++} (l==n){print} END{}" texample.html | sponge texample.html
@@ -30,6 +40,7 @@ wget -qO- "http://texample.net$TEX" | sed -n '/\\begin{document}/,/\\end{documen
montage -geometry "+$PADDING+$PADDING" /tmp/bg-src.png /tmp/bg.png "/tmp/bg-$PAGE.png"
rm /tmp/bg{,-src}.png
+if [ $? -ne 0]; then fail; fi
feh -B white --bg-max "/tmp/bg-$PAGE.png"