From 0e0476ddc481397e5b07681aeaf9563dd2c426ad Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Fri, 31 May 2024 10:06:52 +0200 Subject: [PATCH 1/3] safely return --- bins/inbreeding/watch.nu | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 69a5bdef..792cc62a 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -12,6 +12,10 @@ export def main [] { if $p == {} { let p = $path | remove-cache-prefix | parse "{seed}/{exp}" | into record + if $p == {} { + return ($path | remove-cache-prefix) + } + return $"($p.seed | str substring 0..7) ($p.exp) at ($now)" } -- GitLab From 458428f982128def9a033912c7ee8522e1061537 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Fri, 31 May 2024 10:08:37 +0200 Subject: [PATCH 2/3] refactor `path` --- bins/inbreeding/watch.nu | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 792cc62a..44784bb0 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -7,13 +7,15 @@ export def main [] { return } + let path = $path | remove-cache-prefix + let now = date now | format date "%Y-%m-%d %H:%M:%S" - let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record + let p = $path | parse "{seed}/{exp}/{id}" | into record if $p == {} { - let p = $path | remove-cache-prefix | parse "{seed}/{exp}" | into record + let p = $path | parse "{seed}/{exp}" | into record if $p == {} { - return ($path | remove-cache-prefix) + return $path } return $"($p.seed | str substring 0..7) ($p.exp) at ($now)" -- GitLab From 7efc31ebe205f8f33cd01fd389896bc6fa6560d6 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Fri, 31 May 2024 10:08:48 +0200 Subject: [PATCH 3/3] refactor "pretty hash" --- bins/inbreeding/watch.nu | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 44784bb0..6115192b 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -1,6 +1,10 @@ use consts.nu CACHE use path.nu [ "remove-cache-prefix" ] +def pretty-hash []: [ string -> string ] { + str substring 0..7 +} + export def main [] { watch $CACHE { |op, path, new_path| if $op != "Create" { @@ -18,9 +22,9 @@ export def main [] { return $path } - return $"($p.seed | str substring 0..7) ($p.exp) at ($now)" + return $"($p.seed | pretty-hash) ($p.exp) at ($now)" } - $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" + $"($p.seed | pretty-hash) ($p.exp) ($p.id | pretty-hash) at ($now)" } } -- GitLab