Open-Source Wikis

/

fd

/

Fun facts

sharkdp/fd

Fun facts

A few small observations from spelunking through the repository.

The README's headline factoid: a 50% shorter command name

The README calls out, deadpan, that "the command name is 50% shorter than find", with a footnote linking to ripgrep's own self-deprecating "shorter than grep" joke. The two-letter command and the linked footnote have been there since the early commits of README.md.

The 3 KB embedded color palette

src/main.rs carries a DEFAULT_LS_COLORS constant that is one giant string of vivid's "molokai" 8-bit color set. It encodes color rules for around 250 file extensions and special filenames inline. fd uses it as a fallback when the user has no LS_COLORS environment variable set:

let ls_colors = if colored_output {
    Some(LsColors::from_env().unwrap_or_else(|| LsColors::from_string(DEFAULT_LS_COLORS)))
} else {
    None
};

vivid is also a sharkdp project, so this is one sharkdp tool reaching into another.

"Pressing Ctrl-C twice exits NOW"

The ctrlc handler installed by src/walk.rs uses a two-step shutdown: the first SIGINT sets quit_flag and waits for the receiver to drain; a second SIGINT calls ExitCode::KilledBySigint.exit() immediately. On Unix, that exit path also re-raises SIGINT itself (src/exit_codes.rs) so callers see the conventional 130 exit status rather than fd's plain 1.

ctrlc::set_handler(move || {
    quit_flag.store(true, Ordering::Relaxed);
    if interrupt_flag.fetch_or(true, Ordering::Relaxed) {
        // Ctrl-C has been pressed twice, exit NOW
        ExitCode::KilledBySigint.exit();
    }
}).unwrap();

TODO/FIXME archaeology

There are exactly three TODO/FIXME lines in production source (excluding the *TODO=1: rule baked into the LS_COLORS string):

File Line Comment
src/main.rs 38 // FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos
src/output.rs 15, 67, 82, 134 // TODO: this function is performance critical and can probably be optimized (four near-identical copies above the four print functions)
src/output.rs 78 // TODO: support writing raw bytes on unix?

The macOS jemalloc FIXME is the oldest still-living TODO, dating back to issue #498. It is mirrored by a long target-cfg list in Cargo.toml that excludes macOS from tikv-jemallocator.

fd is its own dogfood

The screencast.svg linked from the README's "Demo" section is rendered from doc/screencast.sh, a tiny shell script that cds through directories and runs fd commands. The man page (doc/fd.1) is hand-maintained groff alongside the clap help text, not generated from clap.

The rg_alias_hidden_ignore counter

-u/--unrestricted is bound to a u8 counter rather than a boolean. The reason is buried in src/cli.rs:

#[arg(... action(ArgAction::Count) ...)]
rg_alias_hidden_ignore: u8,

This lets users idiomatically write -uu (a habit borrowed from ripgrep) and have it still parse. The actual logic only checks > 0.

"Argmax" for batch exec

The argmax crate (also sharkdp-maintained) wraps std::process::Command with knowledge of the platform ARG_MAX limit. fd uses it via argmax::Command::args_would_fit in src/exec/mod.rs to flush a batch before the kernel would refuse the call. The ergonomic upshot: fd ... -X cmd "just works" even when there are tens of thousands of matches, transparently splitting into multiple cmd invocations.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Fun facts – fd wiki | Factory