Support previewing favorites
authorSiraaj Khandkar <siraaj@khandkar.net>
Sun, 23 Jan 2022 21:30:40 +0000 (16:30 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sun, 23 Jan 2022 21:30:40 +0000 (16:30 -0500)
home/bin/wallpapers_preview

index 7d92de3..8727517 100755 (executable)
@@ -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
 }
 
This page took 0.02476 seconds and 4 git commands to generate.