aboutsummaryrefslogtreecommitdiff
path: root/i3/bin/setbg-texample
diff options
context:
space:
mode:
authorCamil Staps2017-12-15 14:43:37 +0100
committerCamil Staps2017-12-15 14:43:37 +0100
commitd7ac1726781db42393676974e0dbf002998112f4 (patch)
tree654bc2acbe3a0093c90d2c6a6378055bf90ce556 /i3/bin/setbg-texample
parentInclude .gitignore in stow (diff)
Add setbg-backup with support for randomising a background image
Diffstat (limited to 'i3/bin/setbg-texample')
-rwxr-xr-xi3/bin/setbg-texample16
1 files changed, 3 insertions, 13 deletions
diff --git a/i3/bin/setbg-texample b/i3/bin/setbg-texample
index c603bce..610c54f 100755
--- a/i3/bin/setbg-texample
+++ b/i3/bin/setbg-texample
@@ -7,16 +7,8 @@ FONT_SIZE=20
CURL="curl -s"
-function fail() {
- if [ -f ~/.bg.png ]; then
- feh --bg-max -B white ~/.bg.png
- fi
- exit -1;
-}
-
# Test internet
-timeout 4 wget -q --spider http://texample.net
-if [ $? -ne 0 ]; then fail; fi
+timeout 4 wget -q --spider http://texample.net || setbg-backup
let "SCR_WIDTH -= 2 * $PADDING"
let "SCR_WIDTH /= 2"
@@ -28,8 +20,7 @@ echo "TeXample page: http://texample.net/tikz/examples/all/?page=$PAGE"
# Fetch list of texamples
cd /tmp
-$CURL -o texample.html "http://texample.net/tikz/examples/all/?page=$PAGE"
-if [ $? -ne 0 ]; then fail; fi
+$CURL -o texample.html "http://texample.net/tikz/examples/all/?page=$PAGE" || setbg-backup
EXAMPLES="$(grep '^<dl' texample.html | wc -l)"
awk -v n=0 "BEGIN{srand();n=int(rand()*$EXAMPLES)+1} /^<dl/{l++} (l==n){print} END{}" texample.html | sponge texample.html
@@ -44,7 +35,6 @@ $CURL "http://texample.net$PDF" | convert -size "x$SCR_HEIGHT" -density 300 - /t
$CURL "http://texample.net$TEX" | sed -n '/\\begin{document}/,/\\end{document}/p' | pygmentize -l latex -O font_size=$FONT_SIZE -o /tmp/bg-src.png
montage -geometry "+$PADDING+$PADDING" /tmp/bg-src.png /tmp/bg-page-0.png "/tmp/bg-$PAGE.png"
-rm /tmp/bg-{page-*,src}.png
-if [ $? -ne 0 ]; then fail; fi
+rm /tmp/bg-{page-*,src}.png || setbg-backup
feh -B white --bg-max "/tmp/bg-$PAGE.png"