168 lines
7.4 KiB
Bash
Executable file
168 lines
7.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# ╭───────────────╮
|
|
# │ SWWW-settings │
|
|
# ╰───────────────╯
|
|
export SWWW_TRANSITION_FPS=60
|
|
export SWWW_TRANSITION_STEP=60
|
|
export SWWW_TRANSITION=center
|
|
|
|
# ╭───────────────────────────────────────────────────────────────────────────╮
|
|
# │ Set default excluded directories if SWWW_EXCLUDED_DIRS is not already set │
|
|
# │ Dirs to exclude: Anime, Colorful, Gaming, Gifs, Gruvbox, Logos, Muted, │
|
|
# │ Nordic, Windoof │
|
|
# ╰───────────────────────────────────────────────────────────────────────────╯
|
|
|
|
init() {
|
|
# ─< checking for swww >──────────────────────────────────────────────────────────────────
|
|
if ! command -v swww >/dev/null 2>&1; then
|
|
notify-send "ERROR" "swww was not found on the system"
|
|
exit 1
|
|
fi
|
|
|
|
# ─< Check if swww daemon is running, start if not >─────────────────────────────────────
|
|
if ! pgrep -x "swww-daemon" >/dev/null; then
|
|
notify-send "SWWW" "swww not running - starting it now"
|
|
swww-daemon
|
|
sleep 1 # Give the daemon a second to start
|
|
if ! pgrep -x "swww-daemon" >/dev/null; then
|
|
notify-send "ERROR" "seems like swww didn't start as expected"
|
|
return 1
|
|
fi
|
|
notify-send "SWWW" "started successfully"
|
|
fi
|
|
}
|
|
|
|
randomSwww() {
|
|
: "${SWWW_EXCLUDED_DIRS:=Anime,Colorful,Gaming,Gifs,Logos,Nordic,Windoof}"
|
|
|
|
# if [ -z "$1" ]; then
|
|
# ─< random wallpaper selection >─────────────────────────────────────────────────────────
|
|
local wall_dir="$HOME/.wallpaper"
|
|
|
|
# ─< Create an array of directories to exclude >──────────────────────────────────────────
|
|
IFS=',' read -ra EXCLUDED_DIRS <<<"$SWWW_EXCLUDED_DIRS"
|
|
|
|
# # ─< Build the find command with exclusions >─────────────────────────────────────────────
|
|
# local find_cmd="find \"$wall_dir\" -type f \( -iname \"*.png\" -o -iname \"*.jpg\" -o -iname \"*.jpeg\" -o -iname \"*.gif\" \)"
|
|
#
|
|
# # Add directory exclusions
|
|
# for dir in "${EXCLUDED_DIRS[@]}"; do
|
|
# find_cmd+=" -not \( -path \"$wall_dir/$dir/*\" -prune \)"
|
|
# done
|
|
#
|
|
# # Add final exclusions
|
|
# find_cmd+=" -not -path \"*/\.git/*\""
|
|
#
|
|
# # ─< Select a random picture >────────────────────────────────────────────────────────────
|
|
# local pic=$(eval "$find_cmd" | shuf -n 1)
|
|
# Alternative approach using shopt
|
|
shopt -s globstar nullglob
|
|
local pics=()
|
|
for pic in "$wall_dir"/**/*.{png,jpg,jpeg,gif}; do
|
|
# Skip excluded directories
|
|
for dir in "${EXCLUDED_DIRS[@]}"; do
|
|
[[ $pic == "$wall_dir/$dir/"* ]] && continue 2
|
|
done
|
|
pics+=("$pic")
|
|
done
|
|
|
|
local pic=$(printf "%s\n" "${pics[@]}" | shuf -n 1)
|
|
# Check if we found any picture
|
|
# notify-send "pic" "$pic"
|
|
if [ -z "$pic" ]; then
|
|
notify-send "ERROR" "No wallpapers found in $wall_dir (excluding: $SWWW_EXCLUDED_DIRS)"
|
|
return 1
|
|
fi
|
|
|
|
# # ─< Check if swww daemon is running, start if not >─────────────────────────────────────
|
|
# if ! pgrep -x "swww-daemon" >/dev/null; then
|
|
# notify-send "SWWW" "swww not running - starting it now"
|
|
# swww-daemon
|
|
# sleep 1 # Give the daemon a second to start
|
|
# if ! pgrep -x "swww" >/dev/null; then
|
|
# notify-send "ERROR" "seems like swww didn't start as expected"
|
|
# return 0
|
|
# fi
|
|
# notify-send "SWWW" "started successfully"
|
|
# fi
|
|
|
|
# ─< checking the wall_dir variable >─────────────────────────────────────────────────────
|
|
# if [[ ! -d "$wall_dir" ]]; then
|
|
# notify-send "ERROR" "$wall_dir path not found"
|
|
# return 1
|
|
# fi
|
|
|
|
# ─< executing swww with the random $pic >────────────────────────────────────────────────
|
|
if swww img "$pic" --transition-fps "$SWWW_TRANSITION_FPS" --transition-step "$SWWW_TRANSITION_STEP" --transition-type "$SWWW_TRANSITION"; then
|
|
notify-send " " "Changed wallpaper to ${pic##*/}"
|
|
notify-send " " "Not sourcing from: $SWWW_EXCLUDED_DIRS"
|
|
else
|
|
notify-send "ERROR" "Failed to set wallpaper: $pic"
|
|
return 1
|
|
fi
|
|
# else
|
|
#
|
|
# # Check if file exists
|
|
# if [[ ! -f "$1" ]]; then
|
|
# notify-send "ERROR" "File not found: $1"
|
|
# return 1
|
|
# fi
|
|
#
|
|
# # ─< executing swww with the random $pic >────────────────────────────────────────────────
|
|
# if swww img "$1" --transition-fps "$SWWW_TRANSITION_FPS" --transition-step "$SWWW_TRANSITION_STEP" --transition-type "$SWWW_TRANSITION"; then
|
|
# notify-send " " "Changed wallpaper to ${1##*/}"
|
|
# else
|
|
# notify-send "ERROR" "Failed to set wallpaper: $1"
|
|
# return 1
|
|
# fi
|
|
# fi
|
|
}
|
|
|
|
# Main logic
|
|
if [ -z "$1" ]; then
|
|
init
|
|
# No argument given, use the last wallpaper
|
|
# last_wallpaper_file="$HOME/.last_wallpaper"
|
|
# if [ -f "$last_wallpaper_file" ]; then
|
|
# last_wallpaper=$(cat "$last_wallpaper_file")
|
|
# set_wallpaper "$last_wallpaper"
|
|
# else
|
|
# log_notify "critical" "Error" "No last wallpaper found"
|
|
# exit 1
|
|
# fi
|
|
elif [ "$1" == "random" ]; then
|
|
randomSwww
|
|
# Use a random wallpaper
|
|
# wall_dir="$HOME/.wallpaper"
|
|
# IFS=',' read -ra EXCLUDED_DIRS <<<"$SWWW_EXCLUDED_DIRS"
|
|
# shopt -s globstar nullglob
|
|
# pics=()
|
|
# for pic in "$wall_dir"/**/*.{png,jpg,jpeg,gif}; do
|
|
# for dir in "${EXCLUDED_DIRS[@]}"; do
|
|
# [[ $pic == "$wall_dir/$dir/"* ]] && continue 2
|
|
# done
|
|
# pics+=("$pic")
|
|
# done
|
|
# random_pic=$(printf "%s\n" "${pics[@]}" | shuf -n 1)
|
|
# if [ -z "$random_pic" ]; then
|
|
# log_notify "critical" "Error" "No wallpapers found in $wall_dir (excluding: $SWWW_EXCLUDED_DIRS)"
|
|
# exit 1
|
|
# fi
|
|
# set_wallpaper "$random_pic"
|
|
# echo "$random_pic" >"$HOME/.last_wallpaper"
|
|
else
|
|
# Use the specified path
|
|
if [ -f "$1" ]; then
|
|
# ─< executing swww with the random $pic >────────────────────────────────────────────────
|
|
if swww img "$1" --transition-fps "$SWWW_TRANSITION_FPS" --transition-step "$SWWW_TRANSITION_STEP" --transition-type "$SWWW_TRANSITION"; then
|
|
notify-send " " "Changed wallpaper to ${pic##*/}"
|
|
notify-send " " "Not sourcing from: $SWWW_EXCLUDED_DIRS"
|
|
else
|
|
notify-send "ERROR" "Failed to set wallpaper: $pic"
|
|
return 1
|
|
fi
|
|
else
|
|
log_notify "critical" "Error" "File not found: $1"
|
|
exit 1
|
|
fi
|
|
fi
|