aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-05-20 23:48:21 -0700
committerGravatar Tom Willemse2022-05-20 23:50:02 -0700
commitabc336dea1187f9d115a062d389c7c5ec730c144 (patch)
tree1bae3c2171bc56bbcd76e24a95ecf14fc21c5cfe
downloadpick-random-wallpaper-abc336dea1187f9d115a062d389c7c5ec730c144.tar.gz
pick-random-wallpaper-abc336dea1187f9d115a062d389c7c5ec730c144.zip
Initial commit
-rwxr-xr-xpick-random-wallpaper22
1 files changed, 22 insertions, 0 deletions
diff --git a/pick-random-wallpaper b/pick-random-wallpaper
new file mode 100755
index 0000000..7a2b28c
--- /dev/null
+++ b/pick-random-wallpaper
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+function hc () { herbstclient "$@"; }
+
+function random-wallpaper() {
+ local rootinfo=$(xwininfo -root)
+ local width=$(echo $rootinfo | grep 'Width:' | sed 's/.*Width: \([[:digit:]]\+\).*/\1/')
+ local height=$(echo $rootinfo | grep 'Height:' | sed 's/.*Height: \([[:digit:]]\+\).*/\1/')
+
+ find ~/pictures/wallpaper -type f \
+ \( -wholename "*/${width}x${height}/*" -o -wholename '*/patterns/*' \) \
+ -not -name '*.org' \
+ | shuf -n 1
+}
+
+wallpaper=$(random-wallpaper)
+
+if ! hc attr my_wallpaper >/dev/null 2>&1
+then hc new_attr string my_wallpaper
+fi
+
+feh --bg-tile "$wallpaper" && hc set_attr my_wallpaper "$wallpaper"