Files
ChromiumPywal/generate-theme.sh
2022-03-28 16:37:55 +03:00

65 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
. ~/.cache/wal/colors.sh
DIR=$(dirname "${BASH_SOURCE[0]}")
THEME_DIR="$DIR/GeneratedTheme"
# Converts hex colors into rgb joined with comma
# #fff -> 255, 255, 255
hexToRgb() {
# Remove '#' character from hex color #fff -> fff
plain=${1#*#}
printf "%d, %d, %d" 0x${plain:0:2} 0x${plain:2:2} 0x${plain:4:2}
}
if [ ! -d $THEME_DIR ]; then
mkdir $THEME_DIR
fi
if [ ! -d "$THEME_DIR/images" ]; then
mkdir "$THEME_DIR/images"
fi
# Copy wallpaper so it can be used in theme
background_image="images/theme_ntp_background_norepeat.png"
cp "$wallpaper" "$THEME_DIR/$background_image"
# Theme template
cat > "$THEME_DIR/manifest.json" << EOF
{
"manifest_version": 3,
"version": "1.0",
"name": "Pywal Theme",
"theme": {
"images": {
"theme_ntp_background" : "$background_image"
},
"colors": {
"frame": [$(hexToRgb $background)],
"frame_inactive": [$(hexToRgb $background)],
"toolbar": [$(hexToRgb $color11)],
"ntp_text": [$(hexToRgb $foreground)],
"ntp_link": [$(hexToRgb $color11)],
"ntp_section": [$(hexToRgb $color8)],
"button_background": [$(hexToRgb $foreground)],
"toolbar_button_icon": [$(hexToRgb $foreground)],
"toolbar_text": [$(hexToRgb $foreground)],
"omnibox_background": [$(hexToRgb $background)],
"omnibox_text": [$(hexToRgb $foreground)]
},
"properties": {
"ntp_background_alignment": "bottom"
}
}
}
EOF
# Remove cache so chrome will refresh theme colors on restart
if [ -f "$THEME_DIR/Cached Theme.pak" ]; then
rm "$THEME_DIR/Cached Theme.pak"
fi
echo "Theme generated at $THEME_DIR"