17 releases (breaking)
0.13.0 | Nov 20, 2022 |
---|---|
0.11.1 | Aug 2, 2022 |
0.11.0 | Jul 27, 2022 |
0.9.0 | Feb 13, 2022 |
0.3.0 | Dec 15, 2018 |
#57 in Command-line interface
49,824 downloads per month
Used in 50 crates
(16 directly)
56KB
1K
SLoC
lscolors

A cross-platform library for colorizing paths according to the LS_COLORS
environment variable (like ls
).
Usage
use lscolors::{LsColors, Style};
let lscolors = LsColors::from_env().unwrap_or_default();
let path = "some/folder/test.tar.gz";
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));
// If you want to use `nu-ansi-term` (fork of ansi_term):
let ansi_style = style.map(Style::to_nu_ansi_term_style)
.unwrap_or_default();
println!("{}", ansi_style.paint(path));
Command-line application
This crate also comes with a small command-line program lscolors
that
can be used to colorize the output of other commands:
> find . -maxdepth 2 | lscolors
> rg foo -l | lscolors
You can install it by running cargo install lscolors
or by downloading one
of the prebuilt binaries from the release page.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
References
Information about the LS_COLORS
environment variable is sparse. Here is a short list of useful references:
LS_COLORS
implementation in the GNU coreutils version ofls
(the reference implementation)LS_COLORS
implementation inbfs
by @tavianator- The
DIR_COLORS(5)
man page
Dependencies
~0.2–4MB
~60K SLoC