From d061650f1de1e65c1a3dc979834286192bef80f8 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 17 Jan 2022 10:31:07 -0500 Subject: [PATCH] Refactor wallpaper_shuffle --- home/bin/randline | 7 +++++++ home/bin/wallpaper_shuffle | 18 +----------------- home/lib/login_variables.sh | 1 + 3 files changed, 9 insertions(+), 17 deletions(-) create mode 100755 home/bin/randline 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 '%' -- 2.20.1