-
-
Notifications
You must be signed in to change notification settings - Fork 939
Open
Labels
Description
Summary
Currently, fd provides placeholders for:
{}→ full path{.}→ path without extension{/}→ basename{/.}→ basename without extension
…but there’s no placeholder for just the file extension.
This makes it awkward to use --exec or --exec-batch commands that depend solely on a file’s extension (e.g. converting, filtering, or renaming files by type), since users must rely on shell-specific parameter expansion.
Problem
Example:
fd . -x echo '{.}'prints the path without the extension.
There’s no way to easily get just:
txt
jpg
rs
Without resorting to shell tricks like:
fd . -x bash -c 'echo "${1##*.}"' _ {}This limits usability, readability, and portability—especially on non-POSIX shells.
Proposed solution
Introduce a new placeholder to capture just the file extension:
| Placeholder | Meaning |
|---|---|
| {.ext} | Extension of the full path (e.g. "txt" for "dir/file.txt") |
| {/.ext} | Extension of the basename only (e.g. "txt" for "file.txt") |
Example usage
fd . -x echo '{.ext}'
# Output:
# txt
# jpg
# mdImplementation concept
In src/exec/mod.rs, extend the placeholder handling logic:
"{.ext}" => match full_path.extension() {
Some(ext) => ext.to_string_lossy().into_owned(),
None => String::new(),
},
"{/.ext}" => match file_name.extension() {
Some(ext) => ext.to_string_lossy().into_owned(),
None => String::new(),
},Benefits
- Improves parity with existing
{.}/{/.}placeholders. - Enables concise, readable, and portable
fd --execone-liners. - Keeps extension logic inside
fd, avoiding shell-specific syntax.