From 615fe54df10d2fc124b84aff89be68469301b2a2 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 5 Aug 2024 12:14:24 -0500 Subject: [PATCH] some more cleanup --- bin/gpg-key-to-datamatrix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/gpg-key-to-datamatrix b/bin/gpg-key-to-datamatrix index 02f540d..e3fdb3e 100755 --- a/bin/gpg-key-to-datamatrix +++ b/bin/gpg-key-to-datamatrix @@ -1,10 +1,14 @@ #! /usr/bin/env nix-shell #! 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] { let flags = [ "--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 length = ($key | bytes length) # 1555 is the maximum length in bytes split data evenly @@ -33,7 +37,7 @@ def main [keyid?: string, outfile = "dmtxdata.pdf"] { $it.item | dmtxwrite -e 8 -o ($tmpdir | path join $"dmtx-($it.index).svg") } - let doc = generate-typst-doc $tmpdir ($byte_chunks | length) + let doc = generate-typst-doc $tmpdir ($byte_chunks | length) $doc | typst compile - $outfile rm -r $tmpdir