From 9b98c4b71befc1dd927a504fe451af7942cd3d95 Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Wed, 16 Oct 2024 22:04:28 -0400 Subject: [PATCH] Added find_in command to search files --- 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 00000000..4f8dc503 --- /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 +}