#cli #linux #terminal #filesystem #color

bin+lib lscolors

Colorize paths using the LS_COLORS environment variable

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

Download history 9066/week @ 2022-12-02 8409/week @ 2022-12-09 6909/week @ 2022-12-16 6935/week @ 2022-12-23 7993/week @ 2022-12-30 8865/week @ 2023-01-06 7561/week @ 2023-01-13 8039/week @ 2023-01-20 10134/week @ 2023-01-27 8552/week @ 2023-02-03 9457/week @ 2023-02-10 10519/week @ 2023-02-17 13457/week @ 2023-02-24 9909/week @ 2023-03-03 13625/week @ 2023-03-10 11379/week @ 2023-03-17

49,824 downloads per month
Used in 50 crates (16 directly)

MIT/Apache

56KB
1K SLoC

lscolors

Build Status Crates.io Documentation

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

at your option.

References

Information about the LS_COLORS environment variable is sparse. Here is a short list of useful references:

Dependencies

~0.2–4MB
~60K SLoC