From f9cb3326c85e911c6024f3ca3fe1b928357b0046 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Mon, 15 May 2017 21:41:31 +0200 Subject: [PATCH] Only parse dir_colors if output is colored, closes #21 --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index fed3f3b..b2d40ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,9 +233,17 @@ fn main() { }; let current_dir = current_dir_buf.as_path(); - let ext_styles = env::home_dir() - .map(|h| h.join(".dir_colors")) - .and_then(|path| parse_dircolors(&path).ok()); + let colored_output = !matches.opt_present("no-color") && + stdout_isatty(); + + let ext_styles = + if colored_output { + env::home_dir() + .map(|h| h.join(".dir_colors")) + .and_then(|path| parse_dircolors(&path).ok()) + } else { + None + }; let config = FdOptions { // The search will be case-sensitive if the command line flag is set or @@ -244,8 +252,7 @@ fn main() { pattern.chars().any(char::is_uppercase), search_full_path: !matches.opt_present("filename"), search_hidden: matches.opt_present("hidden"), - colored: !matches.opt_present("no-color") && - stdout_isatty(), + colored: colored_output, follow_links: matches.opt_present("follow"), max_depth: matches.opt_str("max-depth")