some more cleanup

This commit is contained in:
Daylin Morgan 2024-08-05 12:14:24 -05:00
parent 32729c005e
commit d74ce89b92
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -1,10 +1,14 @@
#! /usr/bin/env nix-shell #! /usr/bin/env nix-shell
#! nix-shell -p typst dmtx-utils nushell -i nu #! nix-shell -p typst dmtx-utils nushell -i nu
def append-if [cond: bool, item: any] {
if $cond { $in | append $item } else { $in }
}
def get-chunked-key [keyid?: string] { def get-chunked-key [keyid?: string] {
let flags = [ let flags = [
"--export-secret-key", "--export-options", "export-minimal" "--export-secret-key", "--export-options", "export-minimal"
] | do { if keyid == null { $in } else { $in | append $keyid}} ] | append-if ($keyid != null) $keyid
let key = (gpg ...$flags) let key = (gpg ...$flags)
let length = ($key | bytes length) let length = ($key | bytes length)
# 1555 is the maximum length in bytes split data evenly # 1555 is the maximum length in bytes split data evenly
@ -25,7 +29,7 @@ def generate-typst-doc [tmp: string, length: int] {
| str join "\n" | str join "\n"
} }
def main [keyid?: string, outfile = "dmtxdata.pdf"] { def main [keyid?: string, --output(-o) = "dmtxdata.pdf"] {
let tmpdir = mktemp -d -p . -t tmp.key-2-matrix-XXX let tmpdir = mktemp -d -p . -t tmp.key-2-matrix-XXX
let byte_chunks = get-chunked-key $keyid let byte_chunks = get-chunked-key $keyid
@ -34,7 +38,7 @@ def main [keyid?: string, outfile = "dmtxdata.pdf"] {
} }
let doc = generate-typst-doc $tmpdir ($byte_chunks | length) let doc = generate-typst-doc $tmpdir ($byte_chunks | length)
$doc | typst compile - $outfile $doc | typst compile - $output
rm -r $tmpdir rm -r $tmpdir
} }