Skip to content
Myr

docs: clarify --exec positional argument handling

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by liruiluo · committed by liruiluo · parent 7027d45 · Browse files · 2 files+13 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−1 removed

  • other:+13 added−1 removed

2 files+13 added−1 removed

modified:src/cli.rs+4 added-1 removed
870 unmodified lines
871 .long_help(872 "Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \873 There is no guarantee of the order commands are executed in, and the order should not be depended upon. \874 All positional arguments following --exec are considered to be arguments to the command - not to fd. \875 It is therefore recommended to place the '-x'/'--exec' option last.\n\875 It is therefore recommended to place the '-x'/'--exec' option last. \876 Use '\\;' to terminate the command template if you need to continue passing fd arguments afterwards.\n\877 The following placeholders are substituted before the command is executed:\n \878 '{}': path (of the current search result)\n \879 '{/}': basename\n \880 '{//}': parent directory\n \
6 unmodified lines
887 - find all *.zip files and unzip them:\n\n \888 fd -e zip -x unzip\n\n \889 - find *.h and *.cpp files and run \"clang-format -i ..\" for each of them:\n\n \890 fd -e h -e cpp -x clang-format -i\n\n \891 - search within `src/` and echo each match (place `-x` last):\n\n \892 fd . src -x echo\n\n \893 - Convert all *.jpg files to *.png files:\n\n \894 fd -e jpg -x convert {} {.}.png\895 ",896 ),
52 unmodified lines
modified:README.md+9 added
187 unmodified lines
188```189Note how the `-i` option to `clang-format` can be passed as a separate argument. This is why190we put the `-x` option last.191192Any positional arguments after `-x` belong to the command template, not to `fd` itself. If you193also want to pass a pattern or search path, put `-x` last:194``` bash195fd pattern path -x echo196```197198Find all `test_*.py` files and open them in your favorite editor:199``` bash200fd -g 'test_*.py' -X vim201```
31 unmodified lines
233234The `-x` and `-X` options take a *command template* as a series of arguments (instead of a single string).235If you want to add additional options to `fd` after the command template, you can terminate it with a `\;`.236237For example, `fd -x echo \; pattern path` treats `pattern path` as `fd` arguments instead of238passing them to `echo`. In practice, it is often clearer to write `fd pattern path -x echo`.239240The syntax for generating commands is similar to that of [GNU Parallel](https://www.gnu.org/software/parallel/):241242- `{}`: A placeholder token that will be replaced with the path of the search result243 (`documents/images/party.jpg`).
555 unmodified lines