mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-01-24 03:19:02 +00:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Duplicates Scripts
|
||||
|
||||
### Definition
|
||||
|
||||
These scripts are used to show how `group-by` can be used to identify duplicate rows. The example shows how that can be used to heuristically find duplicate files.
|
||||
15
dot_config/nushell/nu_scripts/modules/duplicates/example.nu
Normal file
15
dot_config/nushell/nu_scripts/modules/duplicates/example.nu
Normal file
@@ -0,0 +1,15 @@
|
||||
# duplicates example
|
||||
use mod.nu *
|
||||
|
||||
let info = "[{name: "John", lastname: "Doe"}, {name: "John", lastname: "Roe"}, {name: "Jane", lastname: "Soe"}]"
|
||||
print ($info | from json)
|
||||
print ($info | from json | duplicates name)
|
||||
|
||||
#duplicates files example
|
||||
echo A | save A.txt
|
||||
echo A | save B.txt
|
||||
# note that if I used "echo B | save B.txt" the function will give a false positive
|
||||
echo ABC | save C.txt
|
||||
print (ls)
|
||||
print (duplicates files)
|
||||
rm A.txt B.txt C.txt --permanent
|
||||
22
dot_config/nushell/nu_scripts/modules/duplicates/mod.nu
Normal file
22
dot_config/nushell/nu_scripts/modules/duplicates/mod.nu
Normal file
@@ -0,0 +1,22 @@
|
||||
# duplicates returns the rows that correspond to duplicates of the given column.
|
||||
export def duplicates [
|
||||
column: string # Column to look duplicates at
|
||||
--count(-c) # set it to display the number of times the value is repeated.
|
||||
] {
|
||||
group-by {get $column | into string} |
|
||||
transpose |
|
||||
insert count { $in.column1 | flatten | length } |
|
||||
where count > 1 |
|
||||
reject column0 |
|
||||
if ($count | is-empty) { reject count } else { each { $in } } |
|
||||
flatten |
|
||||
flatten
|
||||
}
|
||||
|
||||
# duplicates files recursively finds duplicate files in the current working folder.
|
||||
# It uses a heuristic based on duplicate files having the same size.
|
||||
export def "duplicates files" [] {
|
||||
do -i {ls **/*} | duplicates size
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user