diff options
-rwxr-xr-x | bin/setbg-texample | 19 |
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" |