aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/RofiThemeSelector.sh
diff options
context:
space:
mode:
authorJaKooLit <ejhay.games@gmail.com>2025-02-10 01:16:17 +0900
committerJaKooLit <ejhay.games@gmail.com>2025-02-10 01:16:17 +0900
commitd404c8b6b94d973334a1136223fbf5c412083bdb (patch)
treee7394ffef88af10c76c34e1a3df7481ead33cb49 /config/hypr/scripts/RofiThemeSelector.sh
parent752232f326fd82d28dac4107e5bf81818a657903 (diff)
Initial upload of various rofi themes
Diffstat (limited to 'config/hypr/scripts/RofiThemeSelector.sh')
-rwxr-xr-xconfig/hypr/scripts/RofiThemeSelector.sh75
1 files changed, 75 insertions, 0 deletions
diff --git a/config/hypr/scripts/RofiThemeSelector.sh b/config/hypr/scripts/RofiThemeSelector.sh
new file mode 100755
index 00000000..420316bd
--- /dev/null
+++ b/config/hypr/scripts/RofiThemeSelector.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
+# Script for adding a selected theme to the Rofi config
+
+IFS=$'\n\t'
+
+# Define directories and variables
+rofi_theme_dir="$HOME/.local/share/rofi/themes"
+rofi_config_file="$HOME/.config/rofi/config.rasi"
+SED=$(which sed)
+iDIR="$HOME/.config/swaync/images"
+rofi_theme="$HOME/.config/rofi/config-rofi-theme.rasi"
+
+# Function to display menu options
+menu() {
+ options=()
+ while IFS= read -r file; do
+ options+=("$(basename "$file")")
+ done < <(find "$rofi_theme_dir" -maxdepth 1 -type f -exec basename {} \; | sort)
+
+ printf '%s\n' "${options[@]}"
+}
+
+# Function to add or update theme in the config.rasi
+add_theme_to_config() {
+ local theme_name="$1"
+ local theme_path="$rofi_theme_dir/$theme_name"
+
+ # if config in $HOME to write as $HOME
+ if [[ "$theme_path" == $HOME/* ]]; then
+ theme_path_with_tilde="~${theme_path#$HOME}"
+ else
+ theme_path_with_tilde="$theme_path"
+ fi
+
+ # If no @theme is in the file, add it
+ if ! grep -q '^\s*@theme' "$rofi_config_file"; then
+ echo -e "\n\n@theme \"$theme_path_with_tilde\"" >> "$rofi_config_file"
+ echo "Added @theme \"$theme_path_with_tilde\" to $rofi_config_file"
+ else
+ $SED -i "s/^\(\s*@theme.*\)/\/\/\1/" "$rofi_config_file"
+ echo -e "@theme \"$theme_path_with_tilde\"" >> "$rofi_config_file"
+ echo "Updated @theme line to $theme_path_with_tilde"
+ fi
+
+ # Ensure no more than max # of lines with //@theme lines
+ max_line="9"
+ total_lines=$(grep -c '^\s*//@theme' "$rofi_config_file")
+
+ if [ "$total_lines" -gt "$max_line" ]; then
+ excess=$((total_lines - max_line))
+ # Remove the oldest or the very top //@theme lines
+ for i in $(seq 1 "$excess"); do
+ $SED -i '0,/^\s*\/\/@theme/ { /^\s*\/\/@theme/ {d; q; }}' "$rofi_config_file"
+ done
+ echo "Removed excess //@theme lines"
+ fi
+}
+
+# Main function
+main() {
+ choice=$(menu | rofi rofi -dmenu -i -config $rofi_theme)
+
+ if [[ -z "$choice" ]]; then
+ exit 0
+ fi
+ add_theme_to_config "$choice"
+ notify-send -i "$iDIR/ja.png" -u low 'Rofi Theme' "$choice applied."
+}
+
+if pgrep -x "rofi" >/dev/null; then
+ pkill rofi
+fi
+
+main
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage