Hyprland-dotfiles/waybar/themeswitcher.sh

67 lines
2.7 KiB
Bash
Raw Normal View History

2023-10-09 15:50:47 +02:00
#!/bin/bash
2023-10-10 16:54:41 +02:00
# _____ _ _ _ _
# |_ _| |__ ___ _ __ ___ ___ _____ _(_) |_ ___| |__ ___ _ __
# | | | '_ \ / _ \ '_ ` _ \ / _ \/ __\ \ /\ / / | __/ __| '_ \ / _ \ '__|
# | | | | | | __/ | | | | | __/\__ \\ V V /| | || (__| | | | __/ |
# |_| |_| |_|\___|_| |_| |_|\___||___/ \_/\_/ |_|\__\___|_| |_|\___|_|
#
2024-02-21 08:42:16 +01:00
# by Stephan Raabe (2024)
2023-10-10 16:54:41 +02:00
# -----------------------------------------------------
2023-10-18 16:15:52 +02:00
# -----------------------------------------------------
# Default theme folder
# -----------------------------------------------------
2023-10-10 16:54:41 +02:00
themes_path="$HOME/dotfiles/waybar/themes"
2023-10-18 16:15:52 +02:00
# -----------------------------------------------------
# Initialize arrays
# -----------------------------------------------------
2023-10-09 15:50:47 +02:00
listThemes=""
2023-10-10 16:54:41 +02:00
listNames=""
2024-04-03 11:10:16 +02:00
listNames2=""
2023-10-10 16:54:41 +02:00
# -----------------------------------------------------
# Read theme folder
2024-03-20 11:08:37 +01:00
# -----------------------------------------------------
sleep 0.2
2023-10-10 16:54:41 +02:00
options=$(find $themes_path -maxdepth 2 -type d)
2023-10-09 15:50:47 +02:00
for value in $options
do
2024-02-21 08:42:16 +01:00
if [ ! $value == "$HOME/dotfiles/waybar/themes/assets" ]; then
if [ ! $value == "$themes_path" ]; then
if [ $(find $value -maxdepth 1 -type d | wc -l) = 1 ]; then
result=$(echo $value | sed "s#$HOME/dotfiles/waybar/themes/#/#g")
IFS='/' read -ra arrThemes <<< "$result"
listThemes[${#listThemes[@]}]="/${arrThemes[1]};$result"
if [ -f $themes_path$result/config.sh ]; then
source $themes_path$result/config.sh
listNames+="$theme_name\n"
2024-04-03 11:10:16 +02:00
listNames2+="$theme_name~"
2024-02-21 08:42:16 +01:00
else
listNames+="/${arrThemes[1]};$result\n"
2024-04-03 11:10:16 +02:00
listNames2+="/${arrThemes[1]};$result~"
2024-02-21 08:42:16 +01:00
fi
2023-10-10 16:54:41 +02:00
fi
2023-10-09 15:50:47 +02:00
fi
fi
done
2023-10-09 17:27:03 +02:00
2023-10-10 16:54:41 +02:00
# -----------------------------------------------------
# Show rofi dialog
# -----------------------------------------------------
listNames=${listNames::-2}
2024-03-20 11:24:31 +01:00
choice=$(echo -e "$listNames" | rofi -dmenu -replace -i -config ~/dotfiles/rofi/config-themes.rasi -no-show-icons -width 30 -p "Themes" -format i)
2024-04-03 11:10:16 +02:00
IFS="~"
input=$listNames2
read -ra array <<< "$input"
2023-10-10 16:54:41 +02:00
# -----------------------------------------------------
2023-10-18 16:15:52 +02:00
# Set new theme by writing the theme information to ~/.cache/.themestyle.sh
2023-10-10 16:54:41 +02:00
# -----------------------------------------------------
2023-10-09 17:27:03 +02:00
if [ "$choice" ]; then
2023-11-10 21:12:15 +00:00
echo "Loading waybar theme..."
2023-10-10 16:54:41 +02:00
echo "${listThemes[$choice+1]}" > ~/.cache/.themestyle.sh
2023-10-09 17:27:03 +02:00
~/dotfiles/waybar/launch.sh
2024-04-03 11:10:16 +02:00
notify-send "Waybar Theme changed" "to ${array[$choice]}"
2023-10-09 19:54:14 +02:00
fi