mirror of
https://forge.katzen.cafe/schrottkatze/nix-configs.git
synced 2025-01-09 16:55:51 +01:00
add a criminally stupid cursed fucking template system to this config for automatically editing nix files
This commit is contained in:
parent
ff5e965db1
commit
117bdea98a
2 changed files with 49 additions and 2 deletions
47
build-utils/templ-edit.nu
Executable file
47
build-utils/templ-edit.nu
Executable 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -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";
|
||||||
|
|
Loading…
Reference in a new issue