1
Fork 0
mirror of https://github.com/RGBCube/ThemeNix synced 2025-07-27 16:37:46 +00:00

Add theme generation shell script

This commit is contained in:
RGBCube 2023-11-26 18:42:02 +03:00
parent bba20e4f13
commit 9698f044be
No known key found for this signature in database

71
generate-themes.nu Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env nu
def theme-to-nix [
theme: record, # The theme to convert to Nix.
] {
$theme
| to json
| lines
| each { |line|
if ($line | str trim | str starts-with '"base') {
let line_parts = $line
| str replace '"' ""
| str replace '"' ""
| str replace "," ";"
| split row ": "
let line = $line_parts.0 + " = " + ($line_parts.1 | str upcase)
if not ($line | str ends-with ";") {
$line + ";"
} else {
$line
}
} else {
$line
| str replace "scheme" "name "
| str replace '"' ""
| str replace '"' ""
| str replace ":" " ="
| str replace "," ";"
}
}
| append ""
| str join "\n"
}
def generate-valid-themes [] {
echo "generating themes.nix..."
ls themes
| each { $in.name | str replace ".nix" "" }
| each { |it| ' "' + ($it | path basename) + '" = import "' + $it + '.nix";' }
| prepend "{"
| append "}\n"
| str join "\n"
| save --force themes.nix
}
def main [] {
if not ("base16-schemes" | path exists) {
echo "base16-schemes doesn't exist, cloning..."
git clone https://github.com/tinted-theming/base16-schemes
} else {
echo "base16-schemes exists, updating"
cd base16-schemes
git pull
cd ..
}
ls base16-schemes
| filter { ($in.name | str ends-with ".yml") or ($in.name | str ends-with ".yaml") }
| each { |it|
let new_path = "themes/" + ($it.name | path basename | split row "." | first) + ".nix"
echo $"converting ($it.name) to ($new_path)..."
theme-to-nix (open $it.name) | save --force $new_path
}
generate-valid-themes
}