forked from Shinonome/caelestia-cli
wallpaper: ensure valid image
This commit is contained in:
+11
-7
@@ -1,7 +1,11 @@
|
|||||||
#!/bin/fish
|
#!/bin/fish
|
||||||
|
|
||||||
|
function get-valid-wallpapers
|
||||||
|
identify -ping -format '%i\n' $wallpapers_dir/** 2> /dev/null
|
||||||
|
end
|
||||||
|
|
||||||
set script_name (basename (status filename))
|
set script_name (basename (status filename))
|
||||||
set wallpapers_dir (xdg-user-dir PICTURES)/Wallpapers/
|
set wallpapers_dir (xdg-user-dir PICTURES)/Wallpapers
|
||||||
set threshold 80
|
set threshold 80
|
||||||
|
|
||||||
# Max 0 non-option args | h, f and d are exclusive | F and t are also exclusive
|
# Max 0 non-option args | h, f and d are exclusive | F and t are also exclusive
|
||||||
@@ -40,8 +44,8 @@ else
|
|||||||
if set -q _flag_f
|
if set -q _flag_f
|
||||||
set chosen_wallpaper (realpath $_flag_f)
|
set chosen_wallpaper (realpath $_flag_f)
|
||||||
|
|
||||||
if ! test -f $chosen_wallpaper
|
if ! identify -ping $chosen_wallpaper &> /dev/null
|
||||||
echo "$chosen_wallpaper does not exist"
|
error "$chosen_wallpaper is not a valid image"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,16 +59,16 @@ else
|
|||||||
set -q _flag_d && set wallpapers_dir (realpath $_flag_d)
|
set -q _flag_d && set wallpapers_dir (realpath $_flag_d)
|
||||||
|
|
||||||
if ! test -d $wallpapers_dir
|
if ! test -d $wallpapers_dir
|
||||||
echo "$wallpapers_dir does not exist"
|
error "$wallpapers_dir does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get all files in $wallpapers_dir and exclude the last wallpaper (if it exists)
|
# Get all files in $wallpapers_dir and exclude the last wallpaper (if it exists)
|
||||||
if [ -f "$last_wallpaper_path" ]
|
if [ -f "$last_wallpaper_path" ]
|
||||||
set last_wallpaper (cat $last_wallpaper_path)
|
set last_wallpaper (cat $last_wallpaper_path)
|
||||||
[ -n "$last_wallpaper" ] && set unfiltered_wallpapers (find $wallpapers_dir -type f | grep -v $last_wallpaper)
|
[ -n "$last_wallpaper" ] && set unfiltered_wallpapers (get-valid-wallpapers | grep -v $last_wallpaper)
|
||||||
end
|
end
|
||||||
set -q unfiltered_wallpapers || set unfiltered_wallpapers (find $wallpapers_dir -type f)
|
set -q unfiltered_wallpapers || set unfiltered_wallpapers (get-valid-wallpapers)
|
||||||
|
|
||||||
# Filter by resolution if no filter option is not given
|
# Filter by resolution if no filter option is not given
|
||||||
if set -q _flag_F
|
if set -q _flag_F
|
||||||
@@ -89,7 +93,7 @@ else
|
|||||||
|
|
||||||
# Check if the $wallpapers list is unset or empty
|
# Check if the $wallpapers list is unset or empty
|
||||||
if ! set -q wallpapers || [ -z "$wallpapers" ]
|
if ! set -q wallpapers || [ -z "$wallpapers" ]
|
||||||
echo "No eligible files found in $wallpapers_dir"
|
error "No valid images found in $wallpapers_dir"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user