2024-12-23 16:56:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2025-01-20 12:53:06 +01:00
|
|
|
print_help() {
|
2026-04-21 14:56:31 +02:00
|
|
|
echo "Usage: $program_name INPUT-FILE [OPTION]... "
|
2025-01-20 12:53:06 +01:00
|
|
|
echo
|
|
|
|
|
echo "Changes your current wallpaper"
|
|
|
|
|
echo "Please note that this script is made to be used with the Atlas Desktop and will probably not work on most other desktops."
|
2026-04-21 14:56:31 +02:00
|
|
|
echo
|
|
|
|
|
echo "OPTIONS:"
|
|
|
|
|
echo " -l also apply wallpaper to lockscreen"
|
|
|
|
|
echo
|
2025-01-20 12:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 14:56:31 +02:00
|
|
|
# Handle arguments
|
|
|
|
|
|
|
|
|
|
## Default options
|
|
|
|
|
program_name="$0"
|
|
|
|
|
input_file="$1"
|
|
|
|
|
opt_l=false
|
|
|
|
|
|
|
|
|
|
## No args
|
|
|
|
|
if [ $# -lt 1 ]; then
|
2025-01-20 12:53:06 +01:00
|
|
|
print_help
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-21 14:56:31 +02:00
|
|
|
## Parse args
|
|
|
|
|
shift 2
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
|
case "$arg" in
|
|
|
|
|
"-l")
|
|
|
|
|
opt_l=true
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
print_help
|
|
|
|
|
exit 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2024-12-23 16:56:15 +01:00
|
|
|
# Check if file exists
|
2026-04-21 14:56:31 +02:00
|
|
|
if [ -e "$input_file" ]; then
|
2024-12-23 16:56:15 +01:00
|
|
|
|
|
|
|
|
# Variables declaration
|
|
|
|
|
wallpaper_config=~/.config/hypr/hyprpaper.conf
|
2026-04-21 14:56:31 +02:00
|
|
|
lockscreen_config=~/.config/hypr/hyprlock.conf
|
2024-12-23 16:56:15 +01:00
|
|
|
wallpaper_path=~/.config/hypr/images/wallpaper # Doesn't contain file extension
|
2026-04-21 14:56:31 +02:00
|
|
|
file_extension="${input_file##*.}"
|
2024-12-23 16:56:15 +01:00
|
|
|
|
2025-01-20 12:53:06 +01:00
|
|
|
# In case file has no extension
|
2026-04-21 14:56:31 +02:00
|
|
|
if [ "${file_extension}" == "$input_file" ]; then
|
2025-01-20 12:53:06 +01:00
|
|
|
echo "Error: please provide a file extension (ex: .jpg, .png...)"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-12-23 16:56:15 +01:00
|
|
|
# Remove old wallpaper
|
|
|
|
|
rm $wallpaper_path*
|
|
|
|
|
|
|
|
|
|
# Copy file
|
2026-04-21 14:56:31 +02:00
|
|
|
cp "$input_file" "${wallpaper_path}.${file_extension}"
|
2025-01-20 12:53:06 +01:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
echo "Aborted."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-12-23 16:56:15 +01:00
|
|
|
|
|
|
|
|
# Update config
|
2026-04-21 14:56:31 +02:00
|
|
|
## Wallpaper
|
2024-12-23 16:56:15 +01:00
|
|
|
sed -i "s/wallpaper\.[^[:space:]]*/wallpaper.$file_extension/g" $wallpaper_config # Replace current extension by new extension
|
2025-01-20 12:53:06 +01:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
echo "Aborted."
|
|
|
|
|
exit 1
|
2026-04-21 14:56:31 +02:00
|
|
|
else
|
|
|
|
|
echo "Changed wallpaper !"
|
|
|
|
|
fi
|
|
|
|
|
## Lockscreen
|
|
|
|
|
if [ "$opt_l" == true ]; then
|
|
|
|
|
sed -i "s/wallpaper\.[^[:space:]]*/wallpaper.$file_extension/g" $lockscreen_config # Replace current extension by new extension
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
echo "Aborted."
|
|
|
|
|
echo "Note: Previous actions have not been undone"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "Changed lockscreen !"
|
|
|
|
|
fi
|
2025-01-20 12:53:06 +01:00
|
|
|
fi
|
|
|
|
|
|
2024-12-23 16:56:15 +01:00
|
|
|
# Reload Hyprpaper
|
|
|
|
|
pkill hyprpaper
|
2025-01-20 12:53:06 +01:00
|
|
|
hyprctl dispatch exec hyprpaper > /dev/null # Start hyprpaper and hide stdout output
|
|
|
|
|
# Or you can do the old fashioned way :
|
|
|
|
|
# nohup hyprpaper </dev/null >/dev/null 2>&1 &
|
2024-12-23 16:56:15 +01:00
|
|
|
|
|
|
|
|
echo "Done"
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
2026-04-21 14:56:31 +02:00
|
|
|
echo "Couldn't find '${input_file}': No such file or directory"
|
2024-12-23 16:56:15 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|