Created
May 3, 2023 19:37
-
-
Save CoolGoose/a0a868738b01f1d564c900c81326698a to your computer and use it in GitHub Desktop.
Simple chroma based css preferred color scheme generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# Default values | |
light_theme="" | |
dark_theme="" | |
destination_path="assets/css/extended/syntax.css" | |
# Help message | |
usage() { | |
cat <<EOF | |
Usage: $0 [options] [--] [light-theme] [dark-theme] | |
Options: | |
-h, --help Show this help message and exit | |
--light-theme=LIGHT_THEME Set the light theme | |
--dark-theme=DARK_THEME Set the dark theme | |
--destination-path=PATH Set the destination path for the output file | |
Positional arguments: | |
light-theme Light theme (alternative to --light-theme) | |
dark-theme Dark theme (alternative to --dark-theme) | |
EOF | |
} | |
positional_arg_counter=0 | |
# Parse options and arguments | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
--light-theme=*) | |
light_theme="\${1#*=}" | |
positional_arg_counter=$((positional_arg_counter + 1)) | |
shift | |
;; | |
--dark-theme=*) | |
dark_theme="\${1#*=}" | |
positional_arg_counter=$((positional_arg_counter + 1)) | |
shift | |
;; | |
--destination-path=*) | |
destination_path="\${1#*=}" | |
shift | |
;; | |
*) | |
if [[ $positional_arg_counter -eq 0 ]]; then | |
light_theme="$1" | |
elif [[ $positional_arg_counter -eq 1 ]]; then | |
dark_theme="$1" | |
else | |
echo "Error: Too many arguments" >&2 | |
usage | |
exit 1 | |
fi | |
positional_arg_counter=$((positional_arg_counter + 1)) | |
shift | |
;; | |
esac | |
done | |
if [[ -z "$light_theme" ]] || [[ -z "$dark_theme" ]]; then | |
echo "Error: Missing arguments" >&2 | |
usage | |
exit 1 | |
fi | |
hugo gen chromastyles --style="$light_theme" > "$destination_path" | |
{ | |
echo "@media (prefers-color-scheme: dark) {" | |
hugo gen chromastyles --style="$dark_theme" | sed -E 's/(^\/\*[^*]*\*\/)?(.+)/\1 .dark\2/' | |
echo "}" | |
} >> "$destination_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment