Skip to content
Snippets Groups Projects

make `inbreeding watch` better and more robust

Merged STEVAN Antoine requested to merge inbreeding-watch into main
1 file
+ 14
4
Compare changes
  • Side-by-side
  • Inline
+ 14
4
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)"
}
}
Loading