diff --git a/Cargo.lock b/Cargo.lock index 990e9d5a19..1d6508ed14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3245,6 +3245,7 @@ dependencies = [ "nu-engine", "nu-json", "nu-parser", + "nu-path", "nu-pretty-hex", "nu-protocol", "nu-table", diff --git a/crates/nu-explore/Cargo.toml b/crates/nu-explore/Cargo.toml index f980467e32..fe9caf2aa1 100644 --- a/crates/nu-explore/Cargo.toml +++ b/crates/nu-explore/Cargo.toml @@ -16,6 +16,7 @@ workspace = true [dependencies] nu-protocol = { path = "../nu-protocol", version = "0.98.1" } nu-parser = { path = "../nu-parser", version = "0.98.1" } +nu-path = { path = "../nu-path", version = "0.98.1" } nu-color-config = { path = "../nu-color-config", version = "0.98.1" } nu-engine = { path = "../nu-engine", version = "0.98.1" } nu-table = { path = "../nu-table", version = "0.98.1" } diff --git a/crates/nu-explore/src/explore.rs b/crates/nu-explore/src/explore.rs index d6a59ee083..5384e0fcec 100644 --- a/crates/nu-explore/src/explore.rs +++ b/crates/nu-explore/src/explore.rs @@ -72,6 +72,9 @@ impl Command for Explore { explore_config.table.separator_style = lookup_color(&style_computer, "separator"); let lscolors = create_lscolors(engine_state, stack); + let cwd = engine_state.cwd(Some(stack)).map_or(String::new(), |path| { + path.to_str().unwrap_or("").to_string() + }); let config = PagerConfig::new( &nu_config, @@ -80,6 +83,7 @@ impl Command for Explore { &lscolors, peek_value, tail, + &cwd, ); let result = run_pager(engine_state, &mut stack.clone(), input, config); diff --git a/crates/nu-explore/src/nu_common/lscolor.rs b/crates/nu-explore/src/nu_common/lscolor.rs index 491d2c3f3a..393ace7883 100644 --- a/crates/nu-explore/src/nu_common/lscolor.rs +++ b/crates/nu-explore/src/nu_common/lscolor.rs @@ -1,7 +1,10 @@ +use std::path::Path; + use super::NuText; use lscolors::LsColors; use nu_ansi_term::{Color, Style}; use nu_engine::env_to_string; +use nu_path::{expand_path_with, expand_to_real_path}; use nu_protocol::engine::{EngineState, Stack}; use nu_utils::get_ls_colors; @@ -14,7 +17,7 @@ pub fn create_lscolors(engine_state: &EngineState, stack: &Stack) -> LsColors { } /// Colorizes any columns named "name" in the table using LS_COLORS -pub fn lscolorize(header: &[String], data: &mut [Vec], lscolors: &LsColors) { +pub fn lscolorize(header: &[String], data: &mut [Vec], cwd: &str, lscolors: &LsColors) { for (col, col_name) in header.iter().enumerate() { if col_name != "name" { continue; @@ -23,7 +26,7 @@ pub fn lscolorize(header: &[String], data: &mut [Vec], lscolors: &LsColo for row in data.iter_mut() { let (path, text_style) = &mut row[col]; - let style = get_path_style(path, lscolors); + let style = get_path_style(path, cwd, lscolors); if let Some(style) = style { *text_style = text_style.style(style); } @@ -31,9 +34,29 @@ pub fn lscolorize(header: &[String], data: &mut [Vec], lscolors: &LsColo } } -fn get_path_style(path: &str, ls_colors: &LsColors) -> Option