Skip to content

Commit

Permalink
Add --format to help in README
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed May 8, 2024
1 parent 36163f9 commit fcaff0f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ Options:
--changed-within <date|dur> Filter by file modification time (newer than)
--changed-before <date|dur> Filter by file modification time (older than)
-o, --owner <user:group> Filter by owning user and/or group
--format <fmt> Print results according to template
-x, --exec <cmd>... Execute a command for each search result
-X, --exec-batch <cmd>... Execute a command with all search results at once
-c, --color <when> When to use colors [default: auto] [possible values: auto,
Expand Down

3 comments on commit fcaff0f

@Hrxn
Copy link

@Hrxn Hrxn commented on fcaff0f May 8, 2024

Choose a reason for hiding this comment

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

Is there an example/further documentation on how such a format template would look like?

I could not find anything in this repo, so far.

@tmccombs
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The man page and long form help --help include more documentation. But in short, it uses the same format as --exec.

@Hrxn
Copy link

@Hrxn Hrxn commented on fcaff0f May 8, 2024

Choose a reason for hiding this comment

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

Okay, thanks..

I think I've found it..

PS C:\> fd --help | sls '--exec\s' -Context 2,28

            Print results according to template

>   -x, --exec <cmd>...
            Execute a command for each search result in parallel (use --threads=1 for sequential
            command execution). There is no guarantee of the order commands are executed in, and the
>           order should not be depended upon. All positional arguments following --exec are
            considered to be arguments to the command - not to fd. It is therefore recommended to
            place the '-x'/'--exec' option last.
            The following placeholders are substituted before the command is executed:
              '{}':   path (of the current search result)
              '{/}':  basename
              '{//}': parent directory
              '{.}':  path without file extension
              '{/.}': basename without file extension
              '{{':   literal '{' (for escaping)
              '}}':   literal '}' (for escaping)

            If no placeholder is present, an implicit "{}" at the end is assumed.

            Examples:

              - find all *.zip files and unzip them:

                  fd -e zip -x unzip

              - find *.h and *.cpp files and run "clang-format -i .." for each of them:

                  fd -e h -e cpp -x clang-format -i

              - Convert all *.jpg files to *.png files:

                  fd -e jpg -x convert {} {.}.png

    -X, --exec-batch <cmd>...

PS C:\>

Now I only need to find a good use case for --format ^^

Please sign in to comment.