From: Siraaj Khandkar Date: Mon, 17 Jan 2022 15:31:07 +0000 (-0500) Subject: Refactor wallpaper_shuffle X-Git-Url: https://git.xandkar.net/?p=khome.git;a=commitdiff_plain;h=d061650f1de1e65c1a3dc979834286192bef80f8 Refactor wallpaper_shuffle --- diff --git a/home/bin/randline b/home/bin/randline new file mode 100755 index 0000000..ccd294f --- /dev/null +++ b/home/bin/randline @@ -0,0 +1,7 @@ +#! /usr/bin/awk -f + +BEGIN {srand()} + +{lines[n++] = $0} + +END {print lines[int(n * rand())]} diff --git a/home/bin/wallpaper_shuffle b/home/bin/wallpaper_shuffle index 1fd851a..0c05d15 100755 --- a/home/bin/wallpaper_shuffle +++ b/home/bin/wallpaper_shuffle @@ -2,20 +2,4 @@ set -e -path=$( - find \ - $@ \ - -type f \ - | awk ' - { - paths[i++] = $0 - } - - END { - srand() - j = int(i * rand()) - print paths[j] - }' -) -printf "$path\n" >&2 -feh --bg-scale "$path" +feh --bg-scale "$(find "$DIR_WALLPAPERS" -type f | randline)" diff --git a/home/lib/login_variables.sh b/home/lib/login_variables.sh index 1fd515b..fe0d1cf 100644 --- a/home/lib/login_variables.sh +++ b/home/lib/login_variables.sh @@ -11,6 +11,7 @@ export DIR_NOTES="$HOME/doc/notes" export DIR_LOG="$HOME/var/log" export DIR_LOG_MPD="$DIR_LOG/mpd" export DIR_NQ="$HOME/var/run/nq" +export DIR_WALLPAPERS="$HOME/arc/img/Wallpapers" # ensure all DIRs exist: env | grep ^DIR_ | awk -F= '{print $2}' | xargs -I% mkdir -p '%'