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

Add file search to find command #630

Merged
merged 14 commits into from
Jun 1, 2024
Merged

Add file search to find command #630

merged 14 commits into from
Jun 1, 2024

Conversation

vinc
Copy link
Owner

@vinc vinc commented May 31, 2024

This PR implement file search in find and rename it --file <pattern> instead of --name <pattern> where <pattern> allow globbing like the shell. In --line <pattern> it is a standard regular expression.

By default find will be equivalent to find "$DIR" --file "*" instead of find --help.

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

find-file

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

It should be possible to do find / --file "*.lsp" --line "print" to recursively search a line pattern inside files matching a file pattern in the path.

It could also be possible to search in more than one path.

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

The find.png screenshot in the doc is not valid anymore because the regex syntax must be escaped since #558 and we introduced a new file in #618 that matches the line pattern in the example.

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

New screenshot for the documentation:

find

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

We can now use both --file and --line to filter in which files we want to search the given lines:

~
> find /tmp --line "list"
/tmp/alice.txt
63: was no one to listen to her, still it was good practice to say it over)
71: there WAS no one listening, this time, as it didn't sound at all the

/tmp/lisp/doc.lsp
9:     (if (nil? s) "" (str " " (if (list? s) (str/join s " ") s))) # args

~
> find /tmp --file "*.lsp" --line "list"
/tmp/lisp/doc.lsp
9:     (if (nil? s) "" (str " " (if (list? s) (str/join s " ") s))) # args

And the code has been refactored to be DRY.

@vinc
Copy link
Owner Author

vinc commented May 31, 2024

Running find lisp inside /tmp would print files with a relative path starting with lisp/ but running find inside /tmp/lisp would print files with an absolute path starting with /tmp/lisp/. This inconsistency is now fixed:

~
> find /tmp/lisp
/tmp/lisp/colors.lsp
/tmp/lisp/doc.lsp
/tmp/lisp/factorial.lsp
/tmp/lisp/fibonacci.lsp
/tmp/lisp/geotime.lsp
/tmp/lisp/pi.lsp
/tmp/lisp/sum.lsp
/tmp/lisp/tak.lsp

~
> /tmp/lisp

/tmp/lisp
> find
colors.lsp
doc.lsp
factorial.lsp
fibonacci.lsp
geotime.lsp
pi.lsp
sum.lsp
tak.lsp

@vinc vinc marked this pull request as ready for review June 1, 2024 09:23
@vinc vinc merged commit 946d7a2 into trunk Jun 1, 2024
1 check passed
@vinc vinc deleted the feature/find branch June 1, 2024 09:23
@vinc vinc mentioned this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant