Files
custum-hyprpanel/scripts/fillThemes.sh
Jas Singh 4cdda38604 Implement framework for custom modules and out of the box custom modules as well. (#213)
* Create declarative module scaffolding

* Added ram module (WIP)

* Updates to options, styling and more.

* Added function for styling custom modules.

* Added utility functions and cleaned up code

* Type and fn name updates.

* Update module utils to handle absent values.

* Added icon color in style2 that was missing.

* Linted utils.ts

* Add CPU module and update RAM module to use /proc/meminfo.

* Added disk storage module.

* Consolidate code

* Added netstat module and removed elements from systray default ignore list.

* Added keyboard layout module.

* Fix hook types and move module to customModules directory

* Added updates modules.

* Spacing updates

* Added weather module.

* Added power menu and power module in bar. Increased update default interval to 6 ours.

* Updated styling of bar buttons, made power menu label toggleable, etc.

* Consolidate code and add dynamic tooltips based on data being used.

* Make default custom mogules matugen compatible

* Update base theme

* Fix custom module background coloring

* Remove testing opacity.

* Update themes to account for new modules

* Update nix stuff for libgtop (Need someone to test this)

* Update nix

* Update fractions to multiplications

* Move styling in style directory

* Implement a polling framework for variables that can dynamically adjust polling intervals.

* Netstat module updates when interface name is changed.

* Readme update
2024-09-02 21:10:59 -07:00

87 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Generated by our good friend Chat Jippity
# Might be inefficient but it works
# Define directories and theme files
THEMES_DIR="$(dirname "$(realpath "$0")")/../themes"
COMPLETE_THEME_FILE="catppuccin_mocha.json"
COMPLETE_SPLIT_THEME_FILE="catppuccin_mocha_split.json"
# Check if jq is installed
if ! command -v jq &>/dev/null; then
echo "jq is required but not installed. Please install jq and try again."
exit 1
fi
# Function to fill missing values
fill_missing_values() {
local complete_theme_file="$1"
local target_theme_file="$2"
# Load complete theme and target theme into variables
complete_theme=$(jq '.' "$complete_theme_file")
target_theme=$(jq '.' "$target_theme_file")
# Create associative arrays to map colors to properties for fast lookup
declare -A color_to_props
declare -A prop_to_color
# Populate color_to_props and prop_to_color arrays from complete theme
while IFS= read -r line; do
key=$(echo "$line" | awk '{print $1}')
value=$(echo "$line" | awk '{print $2}')
color_to_props["$value"]+="$key "
prop_to_color["$key"]="$value"
done < <(echo "$complete_theme" | jq -r 'to_entries[] | "\(.key) \(.value)"')
# Generate filled theme by iterating over complete theme keys
filled_theme="$target_theme"
for key in "${!prop_to_color[@]}"; do
if ! echo "$target_theme" | jq -e ".\"$key\"" &>/dev/null; then
# Find corresponding color if missing in target theme
value="${prop_to_color[$key]}"
corresponding_color=""
# Check if other properties with the same color exist in the target theme
for prop in ${color_to_props["$value"]}; do
if echo "$target_theme" | jq -e ".\"$prop\"" &>/dev/null; then
corresponding_color=$(echo "$target_theme" | jq -r ".\"$prop\"")
break
fi
done
# Add missing property with the corresponding color
if [ -n "$corresponding_color" ]; then
filled_theme=$(echo "$filled_theme" | jq --arg key "$key" --arg value "$corresponding_color" '.[$key] = $value')
echo "Added missing property: $key with value: $corresponding_color to $target_theme_file"
else
# Default action if no corresponding color is found
echo "No corresponding color found for $key; using value from complete theme."
filled_theme=$(echo "$filled_theme" | jq --arg key "$key" --arg value "$value" '.[$key] = $value')
fi
fi
done
# Write the filled theme back to the target file
echo "$filled_theme" >"$target_theme_file"
echo "Filled missing values in $target_theme_file"
}
# Process all theme files in the directory
for file in "$THEMES_DIR"/*.json; do
filename=$(basename "$file")
# Skip the complete theme files
if [[ "$filename" == "$COMPLETE_THEME_FILE" ]] || [[ "$filename" == "$COMPLETE_SPLIT_THEME_FILE" ]]; then
continue
fi
# Determine whether to use split or non-split complete theme
if [[ "$filename" == *"_split"* ]]; then
fill_missing_values "$THEMES_DIR/$COMPLETE_SPLIT_THEME_FILE" "$file"
else
fill_missing_values "$THEMES_DIR/$COMPLETE_THEME_FILE" "$file"
fi
done