From c67a6959fc174a449f1f7ee44c800de24021a7d2 Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Wed, 16 Oct 2024 22:27:23 -0400 Subject: [PATCH] Added find_in command to search files (#972) --- sourced/cool-oneliners/find_in.nu | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 sourced/cool-oneliners/find_in.nu diff --git a/sourced/cool-oneliners/find_in.nu b/sourced/cool-oneliners/find_in.nu new file mode 100644 index 0000000..4f8dc50 --- /dev/null +++ b/sourced/cool-oneliners/find_in.nu @@ -0,0 +1,12 @@ +# Search terms in the specified files and/or folders based on the glob pattern provided. +def "find in" [ + glob: glob, # the glob expression + ...rest: any # terms to search +]: nothing -> table { + glob $glob + | par-each {|e| + open $e | lines | enumerate | rename line data | + find -c [data] ...$rest | + each {|match| {path: ($e | path relative-to $env.PWD), ...$match}} + } | flatten +}