dotfiles/.scripts/set-wallpaper.sh

355 lines
9.2 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
wp_base_dir="$HOME/Images/Wallpapers/Desktop"
declare -A wp_dirs=([SFW]="$wp_base_dir/SFW"
[NSFW]="$wp_base_dir/( ͡° ͜ʖ ͡°)"
[BONK]="$wp_base_dir/Bonk")
function pick_random_wallpaper {
if [[ ${#wp_opts[@]} -eq 0 ]]; then
target_wp_dirs=("${wp_dirs[SFW]}")
else
for opt in "${!wp_opts[@]}"; do
opt_value=${wp_opts[$opt]}
if [[ $opt_value -eq 1 ]]; then
target_wp_dirs+=("${wp_dirs[$opt]}")
fi
done
fi
echo "Picking a random wallpaper from ${target_wp_dirs[@]}."
wallpaper="$(find "${target_wp_dirs[@]}" -type f | shuf -n 1)"
wallpaper="$wallpaper"
}
function help {
cat <<- EOF
Usage: $(basename "$0") [options...]
-h, --help Show this message and quit.
-r, --random Change the theme by picking a random wallpaper.
-w, --wallpaper <path> Change the theme using this wallpaper.
-s, --sfw Pick a wallpaper from SFW folder (default).
-n, --nsfw Pick a wallpaper from NSFW folder.
-b, --bonk U horny dog ¬‿¬.
Options -s and -n can be used together.
If no option is specified, reloads the current theme.
EOF
}
declare -A wp_opts
while getopts "hrw:snb" opt; do
case $opt in
h)
help
exit
;;
r)
opt_random=1
;;
w)
opt_wallpaper=1
opt_wallpaper_arg="$OPTARG"
;;
s)
wp_opts[SFW]=1
;;
n)
wp_opts[NSFW]=1
;;
b)
wp_opts[BONK]=1
;;
\?)
echo "Invalid option: $opt."
exit 1
;;
esac
done
# Set/pick wallpaper accordingly to arguments passed
if [[ $opt_random -eq 1 && $opt_wallpaper -eq 1 ]]; then
echo "Option -r and -w can't be used together."
exit 1
elif [[ $opt_random -eq 1 ]]; then
pick_random_wallpaper
elif [[ $opt_wallpaper -eq 1 ]]; then
if [[ -f "$opt_wallpaper_arg" ]]; then
wallpaper="$opt_wallpaper_arg"
else
echo "Error: $opt_wallpaper_arg is not a valid path."
exit 1
fi
else
if [[ $# -gt 0 ]]; then
echo "Warning: Neither -r or -w were specified, ignoring option(s): $*."
fi
# To get the current wallpaper
source "$HOME/.cache/wal/colors.sh"
fi
echo "Selected wallpaper: $wallpaper"
# Create the colors scheme
echo "Generating color scheme using pywal."
wal -qni "$wallpaper" --saturate 0.75
# Replace apostrophes around the wallpaper path with quotes
# in case there is an apostrophe in the file name
sed -iE "/^wallpaper=/,/#/ s/='/=\"/" "$HOME/.cache/wal/colors.sh"
sed -iE "/^wallpaper=/,/#/ s/'$/\"/" "$HOME/.cache/wal/colors.sh"
# Source colors scheme generated
source "$HOME/.cache/wal/colors.sh"
# Set additional colors
accent1_dark_hsl="$(pastel darken 1 "$color5" | pastel format hsl)"
accent2_dark_hsl="$(pastel darken 1 "$color6" | pastel format hsl)"
declare -A colors=(
[foreground]="$foreground"
[good]="#00BB66"
[bad]="#AA2222"
[urgent]="$color4"
[accent1]="$color5"
[accent2]="$color6"
[background1]="$(pastel lighten 0.2 "$accent1_dark_hsl" | pastel format hex)"
[background2]="$(pastel lighten 0.2 "$accent2_dark_hsl" | pastel format hex)"
[hovered]="$(pastel lighten 0.25 "$accent1_dark_hsl" | pastel format hex)"
[selected]="$(pastel lighten 0.35 "$accent1_dark_hsl" | pastel format hex)"
[disabled]="$(pastel lighten 0.35 "$accent1_dark_hsl" | pastel format hex)"
[disabled2]="$(pastel lighten 0.35 "$accent2_dark_hsl" | pastel format hex)"
)
declare -A params=(
[border_radius]=4
[border_size]=2
[gaps_out]=15
[gaps_in]=8
[font]="'JetBrainsMono Nerd Font'"
)
# Display accent colors
# pastel color "${colors[accent1]}"
# pastel color "${colors[accent2]}"
# Clear colors/params files
echo -n '' > "$HOME/.config/gtk-3.0/colors-gtk.css"
echo -n '' > "$HOME/.config/hypr/colors.conf"
echo "wallpaper=\"$wallpaper\"" > "$HOME/.cache/colors.sh"
# Set colors variables in files
echo "Writing theme colors in files."
for key in "${!colors[@]}"; do
value="${colors[$key]}"
# Hyprland
echo '$'"$key=rgb(${value:1})" >> "$HOME/.config/hypr/colors.conf"
# GTK
echo "@define-color $key $value;" >> "$HOME/.config/gtk-3.0/colors-gtk.css"
# Shell
echo "${key}=$value" >> "$HOME/.cache/colors.sh"
# i3
sed -i "s/^set \$$key.*/set \$$key $value/" "$HOME/.config/i3/config"
done
# Add Hyprland/i3 params
echo "Writing parameters to Hyprland & i3 files."
for key in "${!params[@]}"; do
value="${params[$key]}"
# Hyprland
echo '$'"$key=$value" >> "$HOME/.config/hypr/colors.conf"
# i3
sed -i "s/^set \$$key.*/set \$$key $value/" "$HOME/.config/i3/config"
done
# Set Kitty params
echo "Changing colors/params in Kitty config file."
declare -A kitty_vars=(
[font_family]="${params[font]}"
[url_color]="${colors[accent1]}"
[tab_bar_background]="${colors[background1]}"
[active_tab_background]="${colors[selected]}"
[inactive_tab_background]="${colors[hovered]}"
[active_tab_foreground]="${colors[foreground]}"
[inactive_tab_foreground]="${colors[foreground]}"
)
for key in "${!kitty_vars[@]}"; do
value="${kitty_vars[$key]}"
sed -i "s/^$key.*/$key $value/" "$HOME/.config/kitty/kitty.conf"
done
# Set Waybar params
echo "Changing params in Waybar styling file."
declare -A waybar_vars=(
[font-family]="${params[font]}"
[border-bottom]="${params[border_size]}px solid transparent"
[margin-bottom]="${params[border_size]}px"
)
for key in "${!waybar_vars[@]}"; do
value="${waybar_vars[$key]}"
sed -i "s~$key:[^;]*~$key: $value~" "$HOME/.config/waybar/style.css"
done
# Set Wofi params
echo "Changing params in Wofi styling file."
declare -A wofi_vars_window=(
[font-family]="${params[font]}"
[border]="${params[border_size]}px solid transparent"
[border-radius]="${params[border_radius]}px"
)
for key in "${!wofi_vars_window[@]}"; do
value="${wofi_vars_window[$key]}"
sed -i "/^window/,/$key:/ s~$key:[^;]*~$key: $value~" "$HOME/.config/wofi/style.css"
done
declare -A wofi_vars_input=(
[margin]="${params[border_size]}px"
[border-radius]="${params[border_radius]}px ${params[border_radius]}px 0 0"
)
for key in "${!wofi_vars_input[@]}"; do
value="${wofi_vars_input[$key]}"
sed -i "/^#input/,/$key:/ s~$key:[^;]*~$key: $value~" "$HOME/.config/wofi/style.css"
done
# Set entry:selected border-radius
sed -i "/^#entry:selected/,/border-radius:/ s/border-radius:[^;]*/border-radius: $(( params[border_radius]/2 ))px/" "$HOME/.config/wofi/style.css"
# Set Mako params
echo "Changing colors/params in Mako config file."
declare -A mako_vars=(
[font]="${params[font]} 11"
[border-radius]="${params[border_radius]}"
[border-size]="${params[border_size]}"
[outer-margin]="$((params[gaps_out]*2)),$((params[gaps_out]*2)),0,0"
[text-color]="${colors[foreground]}"
[background-color]="${colors[background1]}"
[border-color]="${colors[accent1]}"
)
for key in "${!mako_vars[@]}"; do
value="${mako_vars[$key]}"
sed -i "s/$key=.*/$key=$value/" "$HOME/.config/mako/config"
done
# BetterDiscord
if [[ -x /bin/betterdiscordctl ]]; then
echo "Executable found for betterdiscordctl."
if [[ ! -f "$HOME/.config/BetterDiscord/data/stable/custom.css" ]]; then
echo "Downloading ClearVision theme for BetterDiscord."
mkdir -p "$HOME/.config/BetterDiscord/data/stable"
wget -O "$HOME/.config/BetterDiscord/data/stable/custom.css" "https://betterdiscord.app/Download?id=23"
fi
echo "Changing BetterDiscord theme colors."
declare -A bd_vars=(
[main-color]="${colors[accent1]}"
[hover-color]="${colors[accent2]}"
[text-normal]="${colors[foreground]}"
[background-shading]='0%'
[background-overlay]='rgba(0, 0, 0, 0)'
[background-image]="linear-gradient(160deg, ${colors[background1]}, ${colors[background2]})"
)
for key in "${!bd_vars[@]}"; do
value="${bd_vars[$key]}"
sed -i "s~--$key:[^;]*~--$key: $value~" "$HOME/.config/BetterDiscord/data/stable/custom.css"
done
else
echo "No executable found for betterdiscordctl, skipping."
fi
# Change Wlogout icons color
echo "Changing wlogout icons colors."
wlogout_img=('lock' 'reboot' 'shutdown' 'logout')
for img in "${wlogout_img[@]}"; do
convert "$HOME/.config/wlogout/$img.png" -fill "${colors[accent1]}" -colorize 100 "$HOME/.config/wlogout/$img.png"
convert "$HOME/.config/wlogout/$img-focus.png" -fill "${colors[accent2]}" -colorize 100 "$HOME/.config/wlogout/$img-focus.png"
done
# Reload/restart stuff
if [[ -z "$WAYLAND_DISPLAY" ]]; then
echo "Reloading i3."
i3-msg reload > /dev/null &
echo "Changing wallpaper using feh."
feh --no-fehbg --bg-fill "$wallpaper" &
else
echo "Reloading Hyprland."
hyprctl reload > /dev/null &
if grep -q 1 "$HOME/.cache/weeb-mode"; then
echo "Changing wallpaper using swaybg."
pkill -u "$USER" swaybg &> /dev/null
hyprctl dispatch exec "swaybg -i \"$wallpaper\"" > /dev/null &
fi
if pgrep -u "$USER" waybar > /dev/null; then
echo "Reloading Waybar."
killall -SIGUSR2 waybar &
else
echo "Starting Waybar."
hyprctl dispatch exec waybar > /dev/null &
fi
if pgrep -u "$USER" mako > /dev/null; then
echo "Reloading Mako."
makoctl reload &
else
echo "Starting Mako."
hyprctl dispatch exec mako > /dev/null &
fi
fi
# Reload Kitty
echo "Reloading opened Kitty windows."
killall -SIGUSR1 kitty &> /dev/null &
# Reload pywalfox
#if pgrep -u "$USER" firefox &> /dev/null; then
# echo "Reloading pywalfox."
# pywalfox update &
#fi
# OpenRGB
if [[ -x /bin/openrgb ]]; then
echo "Changing OpenRGB colors."
openrgb --noautoconnect -c "${colors[accent1]:1}" > /dev/null &
fi
# Generate blurred wallpaper to use with swaylock/i3lock
convert "$wallpaper" -blur 0x5 -resize 1920x1080 "$HOME/.cache/wallpaper-blurred.jpg" &