use LS_COLORS for directories

This commit is contained in:
Neel Chotai
2020-02-29 21:31:41 +00:00
parent 58b395e7ee
commit 26ae050f16
4 changed files with 34 additions and 17 deletions
Generated
+10
View File
@@ -186,6 +186,7 @@ dependencies = [
"assert_cli 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "assert_cli 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"terminal_size 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "terminal_size 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -265,6 +266,14 @@ name = "libc"
version = "0.2.66" version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lscolors"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.5.3" version = "0.5.3"
@@ -560,6 +569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3dbf0a8f61baee43a2918ff50ac6a2d3b2c105bc08ed53bc298779f1263409" "checksum jwalk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3dbf0a8f61baee43a2918ff50ac6a2d3b2c105bc08ed53bc298779f1263409"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum lscolors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea3b3414b2d015c4fd689815f2551797f3c2296bb241dd709c7da233ec7cba4b"
"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" "checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9"
"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" "checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
+1
View File
@@ -24,6 +24,7 @@ path = "src/main.rs"
ansi_term = "=0.12" ansi_term = "=0.12"
clap = "=2.33" clap = "=2.33"
jwalk = "0.4.0" jwalk = "0.4.0"
lscolors = "0.6.0"
num_cpus = "1.12" num_cpus = "1.12"
terminal_size = "0.1.10" terminal_size = "0.1.10"
unicode-width = "0.1.7" unicode-width = "0.1.7"
+15 -15
View File
@@ -3,7 +3,7 @@
# Dust # Dust
du + rust = dust. Like du but more intuitive du + rust = dust. Like du but more intuitive.
# Why # Why
@@ -14,21 +14,21 @@ Because I want an easy way to see where my disk is being used.
## Install ## Install
#### Cargo Install #### Cargo
* cargo install du-dust * `cargo install du-dust`
#### Download Install #### Download
* Download linux / mac binary from [Releases](https://github.com/bootandy/dust/releases) * Download Linux/Mac binary from [Releases](https://github.com/bootandy/dust/releases)
* unzip file: tar -xvf _downloaded_file.tar.gz_ * unzip file: `tar -xvf _downloaded_file.tar.gz`
* move file to executable path: sudo mv dust /usr/local/bin/ * move file to executable path: `sudo mv dust /usr/local/bin/`
## Overview ## Overview
Dust is meant to give you an instant overview of which directories are using disk space without requiring sort or head. Dust will print a maximum of 1 'Did not have permissions message'. Dust is meant to give you an instant overview of which directories are using disk space without requiring sort or head. Dust will print a maximum of one 'Did not have permissions message'.
Dust will list a slightly-less-than-the-terminal-height number of the biggest sub directories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest sub directory will have its size shown in *red* Dust will list a slightly-less-than-the-terminal-height number of the biggest subdirectories or files and will smartly recurse down the tree to find the larger ones. There is no need for a '-d' flag or a '-h' flag. The largest subdirectories will be colored.
## Usage ## Usage
@@ -38,12 +38,12 @@ Usage: dust <dir>
Usage: dust <dir> <another_dir> <and_more> Usage: dust <dir> <another_dir> <and_more>
Usage: dust -p <dir> (full-path - does not shorten the path of the subdirectories) Usage: dust -p <dir> (full-path - does not shorten the path of the subdirectories)
Usage: dust -s <dir> (apparent-size - shows the length of the file as opposed to the amount of disk space it uses) Usage: dust -s <dir> (apparent-size - shows the length of the file as opposed to the amount of disk space it uses)
Usage: dust -n 30 <dir> (Shows 30 directories not the default) Usage: dust -n 30 <dir> (shows 30 directories instead of the default)
Usage: dust -d 3 <dir> (Shows 3 levels of subdirectories) Usage: dust -d 3 <dir> (shows 3 levels of subdirectories)
Usage: dust -r <dir> (Reverse order of output, with root at the lowest) Usage: dust -r <dir> (reverse order of output, with root at the lowest)
Usage: dust -x <dir> (Only show directories on same filesystem) Usage: dust -x <dir> (only show directories on the same filesystem)
Usage: dust -X ignore <dir> (Ignore all files and directories with the name 'ignore') Usage: dust -X ignore <dir> (ignore all files and directories with the name 'ignore')
Usage: dust -b <dir> (Do not show percentages or draw the ASCII bars) Usage: dust -b <dir> (do not show percentages or draw ASCII bars)
``` ```
+8 -2
View File
@@ -1,8 +1,9 @@
extern crate ansi_term; extern crate ansi_term;
use self::ansi_term::Colour::Fixed;
use crate::utils::Node; use crate::utils::Node;
use lscolors::{LsColors, Style};
use terminal_size::{terminal_size, Height, Width}; use terminal_size::{terminal_size, Height, Width};
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@@ -287,7 +288,12 @@ pub fn format_string(
}; };
let pretty_size = if is_biggest && display_data.colors_on { let pretty_size = if is_biggest && display_data.colors_on {
format!("{}", Fixed(196).paint(pretty_size)) let lscolors = LsColors::from_env().unwrap_or_default();
let directory_color = lscolors.style_for_indicator(lscolors::Indicator::Directory);
let ansi_style = directory_color
.map(Style::to_ansi_term_style)
.unwrap_or_default();
format!("{}", ansi_style.paint(pretty_size))
} else { } else {
pretty_size pretty_size
}; };