diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c297fd9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.nuon diff=nuon diff --git a/scripts/print-nuon.nu b/scripts/print-nuon.nu new file mode 100755 index 0000000..84c5d42 --- /dev/null +++ b/scripts/print-nuon.nu @@ -0,0 +1,31 @@ +#!/usr/bin/env nu + +def main [file: path]: [ nothing -> string ] { + if not ($file | path exists) { + error make { + msg: $"(ansi red_bold)file_not_found(ansi reset)", + label: { + text: "no such file", + span: (metadata $file).span, + }, + help: $"`($file)` does not exist", + } + } + + let content = open --raw $file + + let data = try { + $content | from nuon + } catch { + error make { + msg: $"(ansi red_bold)invalid_nuon(ansi reset)", + label: { + text: "could not parse NUON", + span: (metadata $file).span, + }, + help: $"`($file)` does not appear to be valid NUON", + } + } + + $data | to nuon -i 4 +} diff --git a/toolkit.nu b/toolkit.nu index 65f6c1c..93de04c 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -31,3 +31,8 @@ export def print-nupm-env [] { print $'NU_LIB_DIRS: ($env.NU_LIB_DIRS?)' print $'NUPM_REGISTRIES: ($env.NUPM_REGISTRIES?)' } + +# turn on pretty diffs for NUON data files +export def set-nuon-diff [] { + git config diff.nuon.textconv (pwd | path join scripts print-nuon.nu) +}