Hyprland-dotfiles/waybar/themeswitcher.sh

67 lines
2.7 KiB
Bash
Raw Permalink Normal View History

2023-10-09 09:50:47 -04:00
#!/bin/bash
2023-10-10 10:54:41 -04:00
# _____ _ _ _ _
# |_ _| |__ ___ _ __ ___ ___ _____ _(_) |_ ___| |__ ___ _ __
# | | | '_ \ / _ \ '_ ` _ \ / _ \/ __\ \ /\ / / | __/ __| '_ \ / _ \ '__|
# | | | | | | __/ | | | | | __/\__ \\ V V /| | || (__| | | | __/ |
# |_| |_| |_|\___|_| |_| |_|\___||___/ \_/\_/ |_|\__\___|_| |_|\___|_|
#
2024-02-21 02:42:16 -05:00
# by Stephan Raabe (2024)
2023-10-10 10:54:41 -04:00
# -----------------------------------------------------
2023-10-18 10:15:52 -04:00
# -----------------------------------------------------
# Default theme folder
# -----------------------------------------------------
2023-10-10 10:54:41 -04:00
themes_path="$HOME/dotfiles/waybar/themes"
2023-10-18 10:15:52 -04:00
# -----------------------------------------------------
# Initialize arrays
# -----------------------------------------------------
2023-10-09 09:50:47 -04:00
listThemes=""
2023-10-10 10:54:41 -04:00
listNames=""
2024-04-03 05:10:16 -04:00
listNames2=""
2023-10-10 10:54:41 -04:00
# -----------------------------------------------------
# Read theme folder
2024-03-20 06:08:37 -04:00
# -----------------------------------------------------
sleep 0.2
2023-10-10 10:54:41 -04:00
options=$(find $themes_path -maxdepth 2 -type d)
2023-10-09 09:50:47 -04:00
for value in $options
do
2024-02-21 02:42:16 -05: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 05:10:16 -04:00
listNames2+="$theme_name~"
2024-02-21 02:42:16 -05:00
else
listNames+="/${arrThemes[1]};$result\n"
2024-04-03 05:10:16 -04:00
listNames2+="/${arrThemes[1]};$result~"
2024-02-21 02:42:16 -05:00
fi
2023-10-10 10:54:41 -04:00
fi
2023-10-09 09:50:47 -04:00
fi
fi
done
2023-10-09 11:27:03 -04:00
2023-10-10 10:54:41 -04:00
# -----------------------------------------------------
# Show rofi dialog
# -----------------------------------------------------
listNames=${listNames::-2}
2024-03-20 06:24:31 -04: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 05:10:16 -04:00
IFS="~"
input=$listNames2
read -ra array <<< "$input"
2023-10-10 10:54:41 -04:00
# -----------------------------------------------------
2023-10-18 10:15:52 -04:00
# Set new theme by writing the theme information to ~/.cache/.themestyle.sh
2023-10-10 10:54:41 -04:00
# -----------------------------------------------------
2023-10-09 11:27:03 -04:00
if [ "$choice" ]; then
2023-11-10 16:12:15 -05:00
echo "Loading waybar theme..."
2023-10-10 10:54:41 -04:00
echo "${listThemes[$choice+1]}" > ~/.cache/.themestyle.sh
2023-10-09 11:27:03 -04:00
~/dotfiles/waybar/launch.sh
2024-04-03 05:10:16 -04:00
notify-send "Waybar Theme changed" "to ${array[$choice]}"
2023-10-09 13:54:14 -04:00
fi