add a criminally stupid cursed fucking template system to this config for automatically editing nix files

This commit is contained in:
Schrottkatze 2025-01-03 17:24:21 +01:00
parent ff5e965db1
commit 117bdea98a
No known key found for this signature in database
2 changed files with 49 additions and 2 deletions

47
build-utils/templ-edit.nu Executable file
View file

@ -0,0 +1,47 @@
#!/usr/bin/env nu
def main [] {}
def "main find" [
file: string
] {
open $file --raw
| lines
| enumerate
| update item {|it| $it.item | parse '{current}#:{name}:-{template}-:#' }
| filter {|it| $it.item | is-not-empty}
| flatten -a
| rename -c { index: line }
}
# TODO: support mroe then single template
def "main edit" [
file: path
name: string
to: string
--preview
] {
let template = main find $file
| where name == $name
| first;
let new = $template.template
| str replace $"%($name)%" $to
| append $" #:($template.name):-($template.template)-:#"
| str join;
let rest = open $file --raw
| lines
| enumerate
| where index != $template.line
| append { index: $template.line, item: $new}
| sort-by index
| reject index
| get item
| append ""
| str join "\n";
if $preview {
print $rest
} else {
$rest | save -f $file
}
}

View file

@ -4,8 +4,8 @@
domain = "forge.katzen.cafe"; domain = "forge.katzen.cafe";
owner = "schrottkatze"; owner = "schrottkatze";
repo = "typst-configs"; repo = "typst-configs";
rev = "569cd8525a85878140baf5952597f27fd7ea51d3"; rev = "569cd8525a85878140baf5952597f27fd7ea51d3"; #:REV:- rev = "%REV%";-:#
sha256 = "sha256-4pAammwrFGhpSquEsh4QSd8Hw/ioHm3fMiC5oqNgbAQ="; sha256 = "sha256-4pAammwrFGhpSquEsh4QSd8Hw/ioHm3fMiC5oqNgbAQ="; #:SHA:- sha256 = "%SHA%";-:#
}; };
flow = pkgs.fetchFromGitHub { flow = pkgs.fetchFromGitHub {
owner = "MultisampledNight"; owner = "MultisampledNight";