From e841c66b3bb4897ecb64453c037e9f0b234b67d2 Mon Sep 17 00:00:00 2001 From: STEVAN Antoine <antoine.stevan@isae-supaero.fr> Date: Fri, 31 May 2024 08:37:42 +0000 Subject: [PATCH] make `inbreeding watch` better and more robust (dragoon/komodo!136) - early return when format is bad twice - refactor --- bins/inbreeding/watch.nu | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 69a5bdef..6115192b 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -1,20 +1,30 @@ 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" { 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 - return $"($p.seed | str substring 0..7) ($p.exp) at ($now)" + let p = $path | parse "{seed}/{exp}" | into record + if $p == {} { + return $path + } + + 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