1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 06:07:44 +00:00

Improved find in: add --exclude flag and properly open files (#1059)

This commit is contained in:
Blake Miner 2025-02-25 08:02:02 -05:00 committed by GitHub
parent 096daa436d
commit f9b9636003
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<string> # 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<path: string, line: int, data: string> {
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