From: Siraaj Khandkar Date: Sun, 23 Jan 2022 21:30:40 +0000 (-0500) Subject: Support previewing favorites X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=cdc33eec197b1a53a1d6ee879617b1f614d6b5c0;p=khome.git Support previewing favorites --- diff --git a/home/bin/wallpapers_preview b/home/bin/wallpapers_preview index 7d92de3..8727517 100755 --- a/home/bin/wallpapers_preview +++ b/home/bin/wallpapers_preview @@ -20,12 +20,10 @@ read_command() { esac } -paths_find() { - local -r root_dir="$1" +paths_set() { local path - IFS=$'\n' - for path in $(find "$root_dir" -type f) + while read -r path do if file "$path" | grep 'image data' > /dev/null then @@ -35,10 +33,17 @@ paths_find() { paths["$(( n - 1 ))"]="$path" fi done - unset IFS printf '\n' >&2 } +paths_set_from_dir_find() { + paths_set < <(find "$1" -type f) +} + +paths_set_from_favs() { + paths_set < <(sort -k 2 "$FILE_WALLPAPER_FAVS" | awk '{sub("^" $1 " +", ""); print}') +} + set_wallpaper() { local -ri i="$1" local -r path="$2" @@ -77,14 +82,17 @@ paths_preview() { } main() { - local root_dir - case "$1" in - '') root_dir="$DIR_WALLPAPERS";; - *) root_dir="$1";; + f | fav) paths_set_from_favs;; + d | dir) paths_set_from_dir_find "$2";; + a | all) paths_set_from_dir_find "$DIR_WALLPAPERS";; + '') + paths_set_from_dir_find "$DIR_WALLPAPERS";; + *) + printf 'Error: unknown source "%s"\n' "$1" >&2 + exit 1;; esac - paths_find "$root_dir" paths_preview }