Updates for the parallel command execution part

[skip ci]
This commit is contained in:
sharkdp 2017-10-22 21:57:20 +02:00 committed by David Peter
parent 5863a5e706
commit 7ecb623950
1 changed files with 17 additions and 19 deletions

View File

@ -97,29 +97,27 @@ complete (and more colorful) variants, see
[here](https://github.com/seebi/dircolors-solarized) or [here](https://github.com/seebi/dircolors-solarized) or
[here](https://github.com/trapd00r/LS_COLORS). [here](https://github.com/trapd00r/LS_COLORS).
## Parallel Command Execution ## Parallel command execution
If the `--exec` flag is specified alongside a command template, a job pool will be created for If the `-x`/`--exec` option is specified alongside a command template, a job pool will be created
generating and executing commands in parallel with each discovered path as the inputs. The syntax for executing commands in parallel for each discovered path as the input. The syntax for generating
for generating commands is similar to that of GNU Parallel: commands is similar to that of GNU Parallel:
- **{}**: A placeholder token that will be replaced with the discovered path. - `{}`: A placeholder token that will be replaced with the path of the search result
- **{.}**: Removes the extension from the path. (`documents/images/party.jpg`).
- **{/}**: Uses the basename of the discovered path. - `{.}`: Like `{}`, but without the file extension (`documents/images/party`).
- **{//}**: Uses the parent of the discovered path. - `{/}`: A placeholder that will be replaced by the basename of the search result (`party.jpg`).
- **{/.}**: Uses the basename, with the extension removed. - `{//}`: Uses the parent of the discovered path (`documents/images`).
- `{/.}`: Uses the basename, with the extension removed (`party`).
```sh ``` bash
# Demonstration of parallel job execution # Convert all jpg files to png files
fd -e flac --exec 'sleep 1; echo $\{SHELL}: {}' fd -e jpg -x 'convert "{}" "{.}.png"'
# This also works, because `SHELL` is not a valid token # Unpack all zip files (if no placeholder is given, the path is appended):
fd -e flac --exec 'sleep 1; echo ${SHELL}: {}' fd -e zip -x unzip
# The token is optional -- it gets added at the end by default. # Convert all flac files into opus files:
fd -e flac --exec 'echo' fd -e flac -x 'ffmpeg -i "{}" -c:a libopus "{.}.opus"'
# Real world example of converting flac files into opus files.
fd -e flac --type f --exec 'ffmpeg -i "{}" -c:a libopus "{.}.opus"'
``` ```
## Install ## Install