dotfiles/.local/bin/sw

340 lines
8.9 KiB
Text
Raw Normal View History

2023-09-26 17:12:28 +02:00
#!/bin/sh
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
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"
#viu -h 15 "$wallpaper"
# Create the colors scheme
echo "Generating color scheme using pywal."
wal -qni "$wallpaper" --saturate 0.75
# Pour si ya un apostrophe dans le nom du fichier
sed -iE "/^wallpaper=/,/#/ s/='/=\"/" /home/viyurz/.cache/wal/colors.sh
sed -iE "/^wallpaper=/,/#/ s/'$/\"/" /home/viyurz/.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]}"
# Set wallpaper using swaybg
if grep 0 "$HOME/.cache/weeb-mode"; then
wallpaper="/usr/share/hyprland/wall_2K.png"
fi
echo "Setting wallpaper using swaybg."
killall -9 swaybg &> /dev/null
hyprctl dispatch exec "swaybg -i \"$wallpaper\"" > /dev/null
# 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/.config/hypr/colors.sh"
# Set colors variables in files
echo "Writing colors to .conf/css/sh 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/.config/hypr/colors.sh"
done
# Add Hyprland params
echo "Adding parameters to Hyprland .conf file."
for key in "${!params[@]}"; do
value="${params[$key]}"
echo '$'"$key=$value" >> "$HOME/.config/hypr/colors.conf"
done
# Reload Hyprland
echo "Reloading Hyprland."
hyprctl reload &> /dev/null
# Set Kitty params
echo "Setting Kitty parameters."
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
echo "Reloading opened Kitties."
killall -SIGUSR1 kitty &> /dev/null
# Convert CSS to SCSS for eww
# echo "Converting CSS colors file to SCSS for eww."
# cp "$HOME/.config/gtk-3.0/colors-gtk.css" "$HOME/.config/eww/colors.scss"
# sed -i -E 's/^@define-color /$/; s/^\$\S*/&:/' "$HOME/.config/eww/colors.scss"
# Set Waybar params
echo "Setting Waybar parameters."
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
echo "Reloading Waybar."
if pgrep -x -u "$USER" waybar > /dev/null; then
killall -SIGUSR2 waybar
else
hyprctl dispatch exec waybar > /dev/null
fi
# Set Wofi params
echo "Setting Wofi parameters."
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 swaync params
#echo "Setting swaync parameters."
#sed -zi "s/border-radius:[^;]*/border-radius: ${params[border_radius]}px/1" "$HOME/.config/swaync/style.css"
#sed -i "s/border: [0-9]+.*/border: ${params[border_size]}px solid transparent;/" "$HOME/.config/swaync/style.css"
#sed -zi "s/margin:[^;]*/margin: $((params[gaps_out]*2))px/1" "$HOME/.config/swaync/style.css"
#sed -zi "s/margin:[^;]*/margin: ${params[gaps_out]}px/3" "$HOME/.config/swaync/style.css"
#sed -zi "s/border-radius:[^;]*/border-radius: ${params[border_radius]}px/8" "$HOME/.config/swaync/style.css"
echo "Reloading swaync."
if pgrep -x -u "$USER" swaync > /dev/null; then
swaync-client -rs > /dev/null
else
hyprctl dispatch exec swaync > /dev/null
fi
# BetterDiscord
if [[ -x /bin/betterdiscordctl ]]; then
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 "Setting BetterDiscord 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
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 pywalfox
if pgrep firefox &> /dev/null; then
echo "Reloading pywalfox."
pywalfox update 2> /dev/null
fi
# OpenRGB
if [[ -x /bin/openrgb ]]; then
echo "Setting keyboard colors."
openrgb --noautoconnect -c "${colors[accent1]:1}" > /dev/null
fi
# To use with swaylock
convert "$wallpaper" -blur 0x5 "$HOME/.cache/wallpaper-blurred.jpg" &