Support setting current
[khome.git] / home / bin / wallpapers_preview
index 8727517..34d98d7 100755 (executable)
@@ -15,7 +15,9 @@ read_command() {
         q | Q) echo 'CMD_QUIT';;
         h | H) echo 'CMD_MOVE_BACK';;
         l | L) echo 'CMD_MOVE_FORWARD';;
-        f | F) echo 'CMD_FAVORITE';;
+        f | F) echo 'CMD_FAVORITE_ADD';;
+        r | R) echo 'CMD_FAVORITE_REMOVE';;
+        s | S) echo 'CMD_SET_CURRENT';;
             *) echo 'CMD_UKNOWN';;
     esac
 }
@@ -73,8 +75,19 @@ paths_preview() {
                 (( i = i == 0 ? (n - 1) : i - 1));;
             CMD_MOVE_FORWARD)
                 (( i = (i + 1) % n ));;
-            CMD_FAVORITE)
+            CMD_FAVORITE_ADD)
+                printf 'Adding to favorites set: "%s"\n' "$path" >&2
                 wallpaper_fav;;
+            CMD_FAVORITE_REMOVE)
+                printf 'Removing from favorites set: "%s"\n' "$path" >&2
+                digest=$(sha256sum "$path" | awk '{print $1}')
+                grep -v "$digest" "$FILE_WALLPAPER_FAVS" \
+                | sort -u \
+                | sponge "$FILE_WALLPAPER_FAVS"
+                ;;
+            CMD_SET_CURRENT)
+                printf 'Setting as current: "%s"\n' "$path" >&2
+                echo "$path" > "$FILE_WALLPAPER_CURR";;
             CMD_UKNOWN)
                 continue;;
         esac
This page took 0.026355 seconds and 4 git commands to generate.