mirror of
https://github.com/RGBCube/random-scripts
synced 2025-05-14 02:54:58 +00:00
feat: speed up linearizer
This commit is contained in:
parent
4c1dfb6f6e
commit
0332398f64
1 changed files with 7 additions and 5 deletions
12
linearize.nu
12
linearize.nu
|
@ -10,16 +10,16 @@ if (ls $root | is-not-empty) {
|
||||||
|
|
||||||
let source = input "enter directory to linearize: "
|
let source = input "enter directory to linearize: "
|
||||||
|
|
||||||
ls ...(glob --no-dir $"($source)/**/*")
|
let linked = ls ...(glob --no-dir $"($source)/**/*")
|
||||||
| where type == file
|
| where type == file
|
||||||
| group-by size | values
|
| group-by size | values
|
||||||
| each {|group|
|
| par-each {|group|
|
||||||
if ($group | length) == 1 {
|
if ($group | length) == 1 {
|
||||||
return $group
|
return $group
|
||||||
}
|
}
|
||||||
|
|
||||||
let by_identity = $group
|
let by_identity = $group
|
||||||
| each { insert hash (open $in.name | hash sha256) }
|
| par-each { insert hash (open $in.name | hash sha256) }
|
||||||
| group-by hash | values
|
| group-by hash | values
|
||||||
|
|
||||||
$by_identity
|
$by_identity
|
||||||
|
@ -33,7 +33,7 @@ ls ...(glob --no-dir $"($source)/**/*")
|
||||||
| each { get 0 }
|
| each { get 0 }
|
||||||
}
|
}
|
||||||
| flatten
|
| flatten
|
||||||
| each {|entry|
|
| par-each {|entry|
|
||||||
let parse = $entry.name | path parse
|
let parse = $entry.name | path parse
|
||||||
|
|
||||||
let date = $entry.modified | format date "%Y-%m-%dT%H:%M:%S"
|
let date = $entry.modified | format date "%Y-%m-%dT%H:%M:%S"
|
||||||
|
@ -42,4 +42,6 @@ ls ...(glob --no-dir $"($source)/**/*")
|
||||||
print $"creating (ansi green)($name)(ansi reset)"
|
print $"creating (ansi green)($name)(ansi reset)"
|
||||||
ln $entry.name ($root | path join $name)
|
ln $entry.name ($root | path join $name)
|
||||||
}
|
}
|
||||||
| ignore
|
| length
|
||||||
|
|
||||||
|
print $"linked a total of (ansi cyan)($linked)(ansi reset) files"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue