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 documentation on find command for Unix newcomers #390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 9 additions & 0 deletions src/Turtle/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,15 @@ inplaceWith sed_ pattern' file = liftIO (runManaged (do
mv tmpfile file ))

-- | Search a directory recursively for all files matching the given `Pattern`
-- Note: The `Pattern` matches against the full path of a file as opposed to
-- just the base name as in GNU find. For example:
--
-- > find "foo.txt" "./bar"
--
-- will return only a single filepath: @./bar/foo.txt@. To search for a
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct? Wouldn't you need to search for the exact string "./bar/foo.txt" to match that path?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh your right! It was originally find "foo.txt" "." and then I went back and updated.

-- filename in a similar manner to GNU find do something similar to:
--
-- > find (suffix $ "/" *> "foo.txt") "./bar"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "/" for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "/" is the file separator for a file path. The intent is to match against ./bar/foo.txt so suffix would match the ./bar then "/" then the file name. I realize though that if one were to have "." as the search-tree root then immediate children ("./foo.txt") wouldn't match. It might have been better to have something like basename "foo.txt" :: Pattern FilePath"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I asked is because find still returns the full name of the path, so I think the closer match to find would be something like:

find (chars <> "/" <> "foo.txt")

find :: Pattern a -> FilePath -> Shell FilePath
find pattern' dir = do
path <- lsif isNotSymlink dir
Expand Down