Announcing lscolors: colorize paths according to the LS_COLORS environment variable

#1

I have recently extracted the ls-like path colorization from my fd tool into a separate crate because I felt that it might be useful for other CLI tools as well. The new crate is called lscolors. You can find more information here:

Docs on docs.rs

The crate can be used like this:

use lscolors::{LsColors, Style};

let lscolors = LsColors::from_env().unwrap_or_default();

let path = "some/folder/archive.zip";
let style = lscolors.style_for_path(path);

// If you want to use `ansi_term`:
let ansi_style = style.map(Style::to_ansi_term_style).unwrap_or_default();
println!("{}", ansi_style.paint(path));

This crate also comes with a small command-line program called lscolors that can be used to colorize the output of other commands, for example:

> find . -maxdepth 2 | lscolors

> rg foo -l | lscolors
3 Likes