aboutsummaryrefslogtreecommitdiff
path: root/bin/xrbg
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-03-15 23:03:03 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-03-15 23:03:03 +1300
commit643a5747fbc54b3180fcd62076c2de4aa9b049b4 (patch)
tree772cd167896f6432e61f2b04d5e37546dada935c /bin/xrbg
parentMake Xresources path configurable (diff)
downloaddotfiles-643a5747fbc54b3180fcd62076c2de4aa9b049b4.tar.gz
dotfiles-643a5747fbc54b3180fcd62076c2de4aa9b049b4.zip
Script for choosing random background on startup
Diffstat (limited to 'bin/xrbg')
-rwxr-xr-xbin/xrbg33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/xrbg b/bin/xrbg
new file mode 100755
index 00000000..9250b20a
--- /dev/null
+++ b/bin/xrbg
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+#
+# xrbg(1) -- Apply a random background image.
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# Copyright: 2016
+# License: Public domain
+#
+self=xrbg
+
+# Path to the backgrounds directory
+bgd=${XBACKGROUNDS:-$HOME/.xbackgrounds}
+
+# Collect all the background images in an array if they
+# match some kosher extensions
+shopt -s nullglob
+declare -a bgs
+bgs=("$bgd"/*)
+
+# If there are no images, warn explicitly and bail
+if ! ((${#bgs[@]})) ; then
+ printf '%s: No background images found in %s\n' \
+ "$self" "$bgd"
+ exit 1
+fi
+
+# Pick one of the images (note shuf(1) needed)
+rbg=$(shuf -en1 "${bgs[@]}") || exit 1
+
+# Apply it as the background and we're done
+feh --bg-scale --no-fehbg -- "$rbg"
+