diff options
author | Tom Willemse | 2022-05-30 23:02:55 -0700 |
---|---|---|
committer | Tom Willemse | 2022-05-30 23:02:55 -0700 |
commit | 6ab43c64aa34c6a13705435f7825d183a59544d8 (patch) | |
tree | accd697043231b2367ce719669d136d66c510fb7 | |
parent | abc336dea1187f9d115a062d389c7c5ec730c144 (diff) | |
download | pick-random-wallpaper-6ab43c64aa34c6a13705435f7825d183a59544d8.tar.gz pick-random-wallpaper-6ab43c64aa34c6a13705435f7825d183a59544d8.zip |
Replace bash script with scsh script
I like scsh better than bash.
-rwxr-xr-x | pick-random-wallpaper | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/pick-random-wallpaper b/pick-random-wallpaper index 7a2b28c..d90af5e 100755 --- a/pick-random-wallpaper +++ b/pick-random-wallpaper @@ -1,22 +1,34 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh +# # -*- mode: scheme; -*- +IFS=" " +exec scsh -s "$0" "$@" +!# -function hc () { herbstclient "$@"; } +(define (random-wallpaper) + (let* ((root-info (let ((port (run/port (xwininfo -root)))) + (reverse (awk (read-line port) (line) ((result '())) + ((seq (or "Width" "Height") ": " + (submatch (+ digit))) => + (lambda (m) + (cons (string->number (match:substring m 1)) + result))))))) + (width (car root-info)) + (height (cadr root-info))) + (string-trim-right + (run/string (pipe (find ,(format #f "~a/pictures/wallpaper" (getenv "HOME")) + -type f + "(" -wholename ,(format #f "*/~ax~a/*" width height) + -o -wholename "*/patterns/*" ")" + -not -name "*.org") + (shuf -n 1)))))) -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/') +(define (attribute-exists? name) + (= 0 (run (herbstclient attr ,name) + (> 1 /dev/null) + (> 2 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" +(let ((wallpaper (random-wallpaper))) + (if (not (attribute-exists? "my_wallpaper")) + (run (herbstclient new_attr string my_wallpaper))) + (&& (feh --bg-tile ,wallpaper) + (herbstclient set_attr my_wallpaper ,wallpaper))) |