diff --git a/README.md b/README.md index 9d8cd15..c7081b2 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,17 @@ commands is similar to that of GNU Parallel: - `{/.}`: Uses the basename, with the extension removed (`party`). ``` bash -# Convert all jpg files to png files -fd -e jpg -x 'convert {} {.}.png' +# Convert all jpg files to png files: +fd -e jpg -x convert {} {.}.png # Unpack all zip files (if no placeholder is given, the path is appended): fd -e zip -x unzip # Convert all flac files into opus files: -fd -e flac -x 'ffmpeg -i {} -c:a libopus {.}.opus' +fd -e flac -x ffmpeg -i {} -c:a libopus {.}.opus + +# Count the number of lines in Rust files (the command template can be terminated with ';'): +fd -x wc -l \; -e rs ``` ## Install diff --git a/doc/fd.1 b/doc/fd.1 index aa52063..41007ae 100644 --- a/doc/fd.1 +++ b/doc/fd.1 @@ -101,21 +101,21 @@ Always colorize output. .BI "\-j, \-\-threads " num Number of threads to use for searching (default: number of available CPUs). .TP -.BI "\-x, \-\-exec " command +.BI "\-x, \-\-exec " command [args...] ; Execute .I command -on each of the discovered path with the following tokens substituted: +for each search result. The following placeholders are substituted by a path derived from the current search result: .RS .IP {} path -.IP {.} -path without extension .IP {/} -basename of path +basename .IP {//} -parent of path +parent directory +.IP {.} +path without file extension .IP {/.} -basename of path without extension +basename without file extension .RE .SH ENVIRONMENT .TP diff --git a/src/app.rs b/src/app.rs index a8da659..fb4b016 100644 --- a/src/app.rs +++ b/src/app.rs @@ -86,6 +86,7 @@ pub fn build_app() -> App<'static, 'static> { .long("exec") .short("x") .multiple(true) + .min_values(1) .allow_hyphen_values(true) .value_terminator(";") .value_name("cmd"), @@ -173,15 +174,17 @@ fn usage() -> HashMap<&'static str, Help> { , "Filter by file extension" , "(Additionally) filter search results by their file extension."); doc!(h, "exec" - , "Execute the given command for each search result" - , "Execute the given command for each search result.\n\ - The following are valid tokens that can be used within the expression for generating \ - commands:\n \ - '{}': places the input in the location of this token\n \ - '{.}': removes the extension from the input\n \ - '{/}': places the basename of the input\n \ - '{//}': places the parent of the input\n \ - '{/.}': places the basename of the input, without the extension"); + , "Execute a command for each search result" + , "Execute a command for each search result.\n\ + All arguments following -exec are are taken to be arguments to the command until the \ + argument ';' is encountered.\n\ + Each occurrence of the following placeholders is substituted by a path derived from the \ + current search result before the command is executed:\n \ + '{}': path\n \ + '{/}': basename\n \ + '{//}': parent directory\n \ + '{.}': path without file extension\n \ + '{/.}': basename without file extension"); doc!(h, "exclude" , "Exclude entries that match the given glob pattern." , "Exclude files/directories that match the given glob pattern. This overrides any \