From 942121c09f78c46e36f35ee1c285a8fe2a157a12 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 18 Jan 2025 17:44:12 +1100 Subject: change-wallpaper -> wallpaper --- change-wallpaper.fish | 104 -------------------------------------------------- main.fish | 2 +- wallpaper.fish | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 105 deletions(-) delete mode 100755 change-wallpaper.fish create mode 100755 wallpaper.fish diff --git a/change-wallpaper.fish b/change-wallpaper.fish deleted file mode 100755 index 0bde3f2..0000000 --- a/change-wallpaper.fish +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/fish - -set script_name (basename (status filename)) -set wallpapers_dir (xdg-user-dir PICTURES)/Wallpapers/ -set threshold 80 - -# Max 0 non-option args | h, f and d are exclusive | F and t are also exclusive -argparse -n 'caelestia-wallpaper' -X 0 -x 'h,f,d' -x 'F,t' \ - 'h/help' \ - 'f/file=!test -f "$_flag_value"' \ - 'd/directory=!test -d "$_flag_value"' \ - 'F/no-filter' \ - 't/threshold=!_validate_int --min 0' \ - -- $argv -or exit - -. (dirname (status filename))/util.fish - -if set -q _flag_h - echo 'Usage:' - echo ' caelestia wallpaper' - echo ' caelestia wallpaper [ -h | --help ]' - echo ' caelestia wallpaper [ -f | --file ]' - echo ' caelestia wallpaper [ -d | --directory ] [ -F | --no-filter ]' - echo ' caelestia wallpaper [ -d | --directory ] [ -t | --threshold ]' - echo - echo 'Options:' - echo ' -h, --help Print this help message and exit' - echo ' -f, --file The file to change wallpaper to' - echo ' -d, --directory The folder to select a random wallpaper from (default '$wallpapers_dir')' - echo ' -F, --no-filter Do not filter by size' - echo ' -t, --threshold The minimum percentage of the size the image must be greater than to be selected (default '$threshold')' -else - set cache_dir $CACHE/wallpaper - - # The path to the last chosen wallpaper - set last_wallpaper_path "$cache_dir/last.txt" - - # Use wallpaper given as argument else choose random - if set -q _flag_f - set chosen_wallpaper "$(cd $(dirname $_flag_f) && pwd)/$(basename $_flag_f)" - - # Set last wallpaper if not same as given - if [ -f "$last_wallpaper_path" ] - set last_wallpaper (cat $last_wallpaper_path) - [ -z "$last_wallpaper" -o "$last_wallpaper" = "$chosen_wallpaper" ] && set -e last_wallpaper - end - else - # The path to the directory containing the selection of wallpapers - set -q _flag_d && set wallpapers_dir $_flag_d - - # Get all files in $wallpapers_dir and exclude the last wallpaper (if it exists) - if [ -f "$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) - end - set -q unfiltered_wallpapers || set unfiltered_wallpapers (find $wallpapers_dir -type f) - - # Filter by resolution if no filter option is not given - if set -q _flag_F - set wallpapers $unfiltered_wallpapers - else - set -l screen_size (hyprctl monitors -j | jq -r 'max_by(.width * .height) | "\(.width)\n\(.height)"') - set -l wall_sizes (identify -ping -format '%w %h\n' $unfiltered_wallpapers) - - # Apply threshold - set -q _flag_t && set threshold $_flag_t - set screen_size[1] (math $screen_size[1] x $threshold / 100) - set screen_size[2] (math $screen_size[2] x $threshold / 100) - - # Add wallpapers that are larger than the screen size * threshold to list to choose from ($wallpapers) - for i in (seq 1 (count $wall_sizes)) - set -l wall_size (string split ' ' $wall_sizes[$i]) - if [ $wall_size[1] -ge $screen_size[1] -a $wall_size[2] -ge $screen_size[2] ] - set -a wallpapers $unfiltered_wallpapers[$i] - end - end - end - - # Check if the $wallpapers list is unset or empty - if ! set -q wallpapers || [ -z "$wallpapers" ] - echo "No eligible files found in $wallpapers_dir" - exit 1 - end - - # Choose a random wallpaper from the $wallpapers list - set chosen_wallpaper (random choice $wallpapers) - end - - # Change the wallpaper and output change if success - hyprctl hyprpaper preload $chosen_wallpaper > /dev/null - for monitor in (hyprctl -j monitors | jq -r '.[].name') - hyprctl hyprpaper wallpaper "$monitor,$chosen_wallpaper" > /dev/null && log "Changed wallpaper on $monitor to $chosen_wallpaper" - end - - # Unload unused wallpapers to preserve memory - hyprctl hyprpaper unload unused > /dev/null - - # Store the wallpaper chosen - mkdir -p $cache_dir - echo $chosen_wallpaper > $last_wallpaper_path - ln -sf $chosen_wallpaper "$cache_dir/current" - magick $chosen_wallpaper -fill black -colorize 10% -blur 0x10 "$cache_dir/blur" -end diff --git a/main.fish b/main.fish index 39bdea1..07f3105 100755 --- a/main.fish +++ b/main.fish @@ -33,7 +33,7 @@ end set valid_subcommands screenshot workspace-action \ clipboard clipboard-delete emoji-picker \ - change-wallpaper pip + wallpaper pip if contains "$argv[1]" $valid_subcommands ./$argv[1].fish $argv[2..] diff --git a/wallpaper.fish b/wallpaper.fish new file mode 100755 index 0000000..0bde3f2 --- /dev/null +++ b/wallpaper.fish @@ -0,0 +1,104 @@ +#!/bin/fish + +set script_name (basename (status filename)) +set wallpapers_dir (xdg-user-dir PICTURES)/Wallpapers/ +set threshold 80 + +# Max 0 non-option args | h, f and d are exclusive | F and t are also exclusive +argparse -n 'caelestia-wallpaper' -X 0 -x 'h,f,d' -x 'F,t' \ + 'h/help' \ + 'f/file=!test -f "$_flag_value"' \ + 'd/directory=!test -d "$_flag_value"' \ + 'F/no-filter' \ + 't/threshold=!_validate_int --min 0' \ + -- $argv +or exit + +. (dirname (status filename))/util.fish + +if set -q _flag_h + echo 'Usage:' + echo ' caelestia wallpaper' + echo ' caelestia wallpaper [ -h | --help ]' + echo ' caelestia wallpaper [ -f | --file ]' + echo ' caelestia wallpaper [ -d | --directory ] [ -F | --no-filter ]' + echo ' caelestia wallpaper [ -d | --directory ] [ -t | --threshold ]' + echo + echo 'Options:' + echo ' -h, --help Print this help message and exit' + echo ' -f, --file The file to change wallpaper to' + echo ' -d, --directory The folder to select a random wallpaper from (default '$wallpapers_dir')' + echo ' -F, --no-filter Do not filter by size' + echo ' -t, --threshold The minimum percentage of the size the image must be greater than to be selected (default '$threshold')' +else + set cache_dir $CACHE/wallpaper + + # The path to the last chosen wallpaper + set last_wallpaper_path "$cache_dir/last.txt" + + # Use wallpaper given as argument else choose random + if set -q _flag_f + set chosen_wallpaper "$(cd $(dirname $_flag_f) && pwd)/$(basename $_flag_f)" + + # Set last wallpaper if not same as given + if [ -f "$last_wallpaper_path" ] + set last_wallpaper (cat $last_wallpaper_path) + [ -z "$last_wallpaper" -o "$last_wallpaper" = "$chosen_wallpaper" ] && set -e last_wallpaper + end + else + # The path to the directory containing the selection of wallpapers + set -q _flag_d && set wallpapers_dir $_flag_d + + # Get all files in $wallpapers_dir and exclude the last wallpaper (if it exists) + if [ -f "$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) + end + set -q unfiltered_wallpapers || set unfiltered_wallpapers (find $wallpapers_dir -type f) + + # Filter by resolution if no filter option is not given + if set -q _flag_F + set wallpapers $unfiltered_wallpapers + else + set -l screen_size (hyprctl monitors -j | jq -r 'max_by(.width * .height) | "\(.width)\n\(.height)"') + set -l wall_sizes (identify -ping -format '%w %h\n' $unfiltered_wallpapers) + + # Apply threshold + set -q _flag_t && set threshold $_flag_t + set screen_size[1] (math $screen_size[1] x $threshold / 100) + set screen_size[2] (math $screen_size[2] x $threshold / 100) + + # Add wallpapers that are larger than the screen size * threshold to list to choose from ($wallpapers) + for i in (seq 1 (count $wall_sizes)) + set -l wall_size (string split ' ' $wall_sizes[$i]) + if [ $wall_size[1] -ge $screen_size[1] -a $wall_size[2] -ge $screen_size[2] ] + set -a wallpapers $unfiltered_wallpapers[$i] + end + end + end + + # Check if the $wallpapers list is unset or empty + if ! set -q wallpapers || [ -z "$wallpapers" ] + echo "No eligible files found in $wallpapers_dir" + exit 1 + end + + # Choose a random wallpaper from the $wallpapers list + set chosen_wallpaper (random choice $wallpapers) + end + + # Change the wallpaper and output change if success + hyprctl hyprpaper preload $chosen_wallpaper > /dev/null + for monitor in (hyprctl -j monitors | jq -r '.[].name') + hyprctl hyprpaper wallpaper "$monitor,$chosen_wallpaper" > /dev/null && log "Changed wallpaper on $monitor to $chosen_wallpaper" + end + + # Unload unused wallpapers to preserve memory + hyprctl hyprpaper unload unused > /dev/null + + # Store the wallpaper chosen + mkdir -p $cache_dir + echo $chosen_wallpaper > $last_wallpaper_path + ln -sf $chosen_wallpaper "$cache_dir/current" + magick $chosen_wallpaper -fill black -colorize 10% -blur 0x10 "$cache_dir/blur" +end -- cgit v1.2.3-freya