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
Provenance
- Commit
2278836- Tree
b2bc6a0- Author
liruiluo <magi.luolirui@gmail.com>- Committer
liruiluo <magi.luolirui@gmail.com>- Parent
7027d45
2 files changed+13 added−1 removed
modified:src/cli.rs+4 added-1 removed
870 unmodified lines871 .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 lines887 - 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 linesmodified:README.md+9 added
187 unmodified lines188 ```189 Note how the `-i` option to `clang-format` can be passed as a separate argument. This is why190 we put the `-x` option last.191 192+Any positional arguments after `-x` belong to the command template, not to `fd` itself. If you193+also want to pass a pattern or search path, put `-x` last:194+``` bash195+fd pattern path -x echo196+```197+198 Find all `test_*.py` files and open them in your favorite editor:199 ``` bash200 fd -g 'test_*.py' -X vim201 ```31 unmodified lines233 234 The `-x` and `-X` options take a *command template* as a series of arguments (instead of a single string).235 If you want to add additional options to `fd` after the command template, you can terminate it with a `\;`.236 237+For example, `fd -x echo \; pattern path` treats `pattern path` as `fd` arguments instead of238+passing them to `echo`. In practice, it is often clearer to write `fd pattern path -x echo`.239+240 The syntax for generating commands is similar to that of [GNU Parallel](https://www.gnu.org/software/parallel/):241 242 - `{}`: A placeholder token that will be replaced with the path of the search result243 (`documents/images/party.jpg`).555 unmodified lines