Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sourced/cool-oneliners/find_in.nu
Original file line number Diff line number Diff line change
@@ -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
Expand Down