From 4de5c4f871cee9502c3ab3c6d40b5e2668600b60 Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Tue, 25 Feb 2025 07:58:50 -0500 Subject: [PATCH] Improved `find in` by adding `--exclude` flag and opening files with `--raw` --- sourced/cool-oneliners/find_in.nu | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sourced/cool-oneliners/find_in.nu b/sourced/cool-oneliners/find_in.nu index 20855edb9..675cd5af4 100644 --- a/sourced/cool-oneliners/find_in.nu +++ b/sourced/cool-oneliners/find_in.nu @@ -1,11 +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 + glob: glob, # The glob expression + --exclude (-e): list # Patterns to exclude from the search: `find in` will not walk the inside of directories matching the excluded patterns. + ...rest: any # Terms to find ]: nothing -> table { - glob --no-dir $glob + glob --exclude $exclude --no-dir $glob | par-each {|e| - open $e | lines | enumerate | rename line data | + open --raw $e | lines | enumerate | rename line data | find --columns [data] ...$rest | each {|match| {path: ($e | path relative-to $env.PWD), ...$match}} } | flatten