Skip to content

Commit

Permalink
allow showing NUON diffs (#91)
Browse files Browse the repository at this point in the history
> Related to diffing the nuon files, inspired by
https://www.youtube.com/watch?v=Md44rcw13k4. Pasting it here from
Discord so it won't get burried:
> * create a new file called .gitattributes
> * put the following like in it `*.nuon diff=nuon`
> * run the following command `git config diff.nuon.textconv nu`
> * modify a NUON file and see how the diff is pretty
>
> _Originally posted by @kubouch in
#86 (comment)
>

## Description
running the following will turn on pretty diffing for NUON files
```nushell
use toolkit.nu
toolkit set-nuon-diff
```

## example
let's diff 4140560 which is a commit part of
#86
```diff
diff --git a/registry/nu_plugin_explore.nuon b/registry/nu_plugin_explore.nuon
index 9b93051..e2a7882 100644
--- a/registry/nu_plugin_explore.nuon
+++ b/registry/nu_plugin_explore.nuon
@@ -1 +1 @@
-[[name, version, path, type, info]; [nu_plugin_explore, "0.1.2", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.1.2"}], [nu_plugin_explore, "0.2.0", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.2.0"}]]
\ No newline at end of file
+[[name, version, path, type, info]; [nu_plugin_explore, "0.1.2", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.1.2"}], [nu_plugin_explore, "0.2.0", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.2.0"}], [nu_plugin_explore, "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89"}], [nu_plugin_explore, "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc"}], [nu_plugin_explore, "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c"}], [nu_plugin_explore, "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1"}], [nu_plugin_explore, "0.93.0", null, git, {url: "https://github.com/amtoine/nu_plugin_explore", revision: "0.93.0"}]]
\ No newline at end of file
diff --git a/registry/registry.nuon b/registry/registry.nuon
index 6c3ee7f..806e8d3 100644
--- a/registry/registry.nuon
+++ b/registry/registry.nuon
@@ -1 +1 @@
-[[name, path, hash]; [nu-clippy, nu-clippy.nuon, "md5-15ccbe07dfb7d5f2de260b2b40bf36b5"], [nu-discord-update, nu-discord-update.nuon, "md5-d593c0f41ffd71873028871fcd74b5a9"], [nu-fonts-install, nu-fonts-install.nuon, "md5-cd57f47aeece1679e2febc438d195e8d"], [nu-git-manager, nu-git-manager.nuon, "md5-4aaae15412fb84233fcb19716f6b7e89"], [nu-git-manager-sugar, nu-git-manager-sugar.nuon, "md5-d0c7641c0b369e7c944cc668741734d9"], [nu-hooks, nu-hooks.nuon, "md5-5368e1bc61e9a567263fa4cc55c29783"], [nu-logout, nu-logout.nuon, "md5-9cb6e927f4823dafa8b48867ef1cf70f"], [nu-monitor-manager, nu-monitor-manager.nuon, "md5-15f64df367e8b59606f9b29347cce8a9"], [nu-pomodoro, nu-pomodoro.nuon, "md5-53e18e3476358a813e3ba289dbc5609c"], [nu-right-prompt, nu-right-prompt.nuon, "md5-8a684d7720f0703943317709abfc87bb"], [nu-scripts, nu-scripts.nuon, "md5-733ba206358f545ba9274854fda1c4a5"], [nu-sound-manager, nu-sound-manager.nuon, "md5-f305740d2e93cfeb76c40302f7f5246a"], [nu-themes, nu-themes.nuon, "md5-e303b8f08b1158aacef80a53c5432662"], [nu-zellij, nu-zellij.nuon, "md5-5b0c46f155261507c08c693366639c7a"], [nu_plugin_audio_hook, nu_plugin_audio_hook.nuon, "md5-b2f7807acf002c5e02e1c43e2f80eb16"], [nu_plugin_clipboard, nu_plugin_clipboard.nuon, "md5-cb9d8d27e8fd1814dce58dd0fdb604e5"], [nu_plugin_desktop_notifications, nu_plugin_desktop_notifications.nuon, "md5-f682e6fd6eecf2743686a3da71c1917c"], [nu_plugin_explore, nu_plugin_explore.nuon, "md5-9f9ecf5bbd943645daaa515210bb113a"], [nu_plugin_image, nu_plugin_image.nuon, "md5-d842828405fa74d1056767fa4c3de248"], [nu_plugin_port_list, nu_plugin_port_list.nuon, "md5-59cf1913f6041f45d8c4b4a99d518501"], [nu_plugin_port_scan, nu_plugin_port_scan.nuon, "md5-c4a8347de871a0f626c78d1b05740e19"], [nu_plugin_qr_maker, nu_plugin_qr_maker.nuon, "md5-3eb8130c45318fe8a90abaf0680574de"], [nupm, nupm_pkg.nuon, "md5-2cf3b52cb9535f74d94d7b68abe0acd1"], [tmux-sessionizer, tmux-sessionizer.nuon, "md5-252d0e1da316ff5f597402d2a2bb09b5"]]
\ No newline at end of file
+[[name, path, hash]; [nu-clippy, nu-clippy.nuon, "md5-15ccbe07dfb7d5f2de260b2b40bf36b5"], [nu-discord-update, nu-discord-update.nuon, "md5-d593c0f41ffd71873028871fcd74b5a9"], [nu-fonts-install, nu-fonts-install.nuon, "md5-cd57f47aeece1679e2febc438d195e8d"], [nu-git-manager, nu-git-manager.nuon, "md5-4aaae15412fb84233fcb19716f6b7e89"], [nu-git-manager-sugar, nu-git-manager-sugar.nuon, "md5-d0c7641c0b369e7c944cc668741734d9"], [nu-hooks, nu-hooks.nuon, "md5-5368e1bc61e9a567263fa4cc55c29783"], [nu-logout, nu-logout.nuon, "md5-9cb6e927f4823dafa8b48867ef1cf70f"], [nu-monitor-manager, nu-monitor-manager.nuon, "md5-15f64df367e8b59606f9b29347cce8a9"], [nu-pomodoro, nu-pomodoro.nuon, "md5-53e18e3476358a813e3ba289dbc5609c"], [nu-right-prompt, nu-right-prompt.nuon, "md5-8a684d7720f0703943317709abfc87bb"], [nu-scripts, nu-scripts.nuon, "md5-733ba206358f545ba9274854fda1c4a5"], [nu-sound-manager, nu-sound-manager.nuon, "md5-f305740d2e93cfeb76c40302f7f5246a"], [nu-themes, nu-themes.nuon, "md5-e303b8f08b1158aacef80a53c5432662"], [nu-zellij, nu-zellij.nuon, "md5-5b0c46f155261507c08c693366639c7a"], [nu_plugin_audio_hook, nu_plugin_audio_hook.nuon, "md5-b2f7807acf002c5e02e1c43e2f80eb16"], [nu_plugin_clipboard, nu_plugin_clipboard.nuon, "md5-cb9d8d27e8fd1814dce58dd0fdb604e5"], [nu_plugin_desktop_notifications, nu_plugin_desktop_notifications.nuon, "md5-f682e6fd6eecf2743686a3da71c1917c"], [nu_plugin_explore, nu_plugin_explore.nuon, "md5-63db3ee7027bb97443b88997b6df5e3d"], [nu_plugin_image, nu_plugin_image.nuon, "md5-d842828405fa74d1056767fa4c3de248"], [nu_plugin_port_list, nu_plugin_port_list.nuon, "md5-59cf1913f6041f45d8c4b4a99d518501"], [nu_plugin_port_scan, nu_plugin_port_scan.nuon, "md5-c4a8347de871a0f626c78d1b05740e19"], [nu_plugin_qr_maker, nu_plugin_qr_maker.nuon, "md5-3eb8130c45318fe8a90abaf0680574de"], [nupm, nupm_pkg.nuon, "md5-2cf3b52cb9535f74d94d7b68abe0acd1"], [tmux-sessionizer, tmux-sessionizer.nuon, "md5-252d0e1da316ff5f597402d2a2bb09b5"]]
\ No newline at end of file
```
becomes
```diff
diff --git a/registry/nu_plugin_explore.nuon b/registry/nu_plugin_explore.nuon
index 9b93051..e2a7882 100644
--- a/registry/nu_plugin_explore.nuon
+++ b/registry/nu_plugin_explore.nuon
@@ -25,5 +25,55 @@
             url: "https://github.com/amtoine/nu_plugin_explore",
             revision: "0.2.0"
         }
+    ],
+    [
+        nu_plugin_explore,
+        "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89",
+        null,
+        git,
+        {
+            url: "https://github.com/amtoine/nu_plugin_explore",
+            revision: "0.92.3-2595f31541554c6d8602ebebc9dffbc4dd29dd89"
+        }
+    ],
+    [
+        nu_plugin_explore,
+        "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc",
+        null,
+        git,
+        {
+            url: "https://github.com/amtoine/nu_plugin_explore",
+            revision: "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc"
+        }
+    ],
+    [
+        nu_plugin_explore,
+        "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c",
+        null,
+        git,
+        {
+            url: "https://github.com/amtoine/nu_plugin_explore",
+            revision: "0.92.3-be5ed3290cb116cbe9f3038f7a2d46aaac85a25c"
+        }
+    ],
+    [
+        nu_plugin_explore,
+        "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1",
+        null,
+        git,
+        {
+            url: "https://github.com/amtoine/nu_plugin_explore",
+            revision: "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1"
+        }
+    ],
+    [
+        nu_plugin_explore,
+        "0.93.0",
+        null,
+        git,
+        {
+            url: "https://github.com/amtoine/nu_plugin_explore",
+            revision: "0.93.0"
+        }
     ]
 ]
diff --git a/registry/registry.nuon b/registry/registry.nuon
index 6c3ee7f..806e8d3 100644
--- a/registry/registry.nuon
+++ b/registry/registry.nuon
@@ -92,7 +92,7 @@
     [
         nu_plugin_explore,
         nu_plugin_explore.nuon,
-        "md5-9f9ecf5bbd943645daaa515210bb113a"
+        "md5-63db3ee7027bb97443b88997b6df5e3d"
     ],
     [
         nu_plugin_image,
```
which i think it muuuuuuch easier to look at 😉
  • Loading branch information
amtoine authored Nov 27, 2024
1 parent 3bc98fd commit c968482
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.nuon diff=nuon
31 changes: 31 additions & 0 deletions scripts/print-nuon.nu
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit c968482

Please sign in to comment.