diff --git a/Cargo.lock b/Cargo.lock index 45201cc688..f51840db71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2843,6 +2843,7 @@ dependencies = [ "fuzzy-matcher", "is_executable", "log", + "lscolors", "miette", "nu-ansi-term", "nu-cmd-base", diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index b07ce265f9..62c531e70b 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -34,6 +34,7 @@ fuzzy-matcher = "0.3" is_executable = "1.0" log = "0.4" miette = { version = "7.0", features = ["fancy-no-backtrace"] } +lscolors = { version = "0.17", default-features = false, features = ["nu-ansi-term"] } once_cell = "1.18" percent-encoding = "2" pathdiff = "0.2" diff --git a/crates/nu-cli/src/completions/completer.rs b/crates/nu-cli/src/completions/completer.rs index 917ffb9c7f..2459fca804 100644 --- a/crates/nu-cli/src/completions/completer.rs +++ b/crates/nu-cli/src/completions/completer.rs @@ -266,8 +266,10 @@ impl NuCompleter { || prev_expr_str == b"overlay use" || prev_expr_str == b"source-env" { - let mut completer = - DotNuCompletion::new(self.engine_state.clone()); + let mut completer = DotNuCompletion::new( + self.engine_state.clone(), + self.stack.clone(), + ); return self.process_completion( &mut completer, @@ -278,8 +280,10 @@ impl NuCompleter { pos, ); } else if prev_expr_str == b"ls" { - let mut completer = - FileCompletion::new(self.engine_state.clone()); + let mut completer = FileCompletion::new( + self.engine_state.clone(), + self.stack.clone(), + ); return self.process_completion( &mut completer, @@ -313,8 +317,10 @@ impl NuCompleter { ); } FlatShape::Directory => { - let mut completer = - DirectoryCompletion::new(self.engine_state.clone()); + let mut completer = DirectoryCompletion::new( + self.engine_state.clone(), + self.stack.clone(), + ); return self.process_completion( &mut completer, @@ -326,8 +332,10 @@ impl NuCompleter { ); } FlatShape::Filepath | FlatShape::GlobPattern => { - let mut completer = - FileCompletion::new(self.engine_state.clone()); + let mut completer = FileCompletion::new( + self.engine_state.clone(), + self.stack.clone(), + ); return self.process_completion( &mut completer, @@ -374,8 +382,10 @@ impl NuCompleter { } // Check for file completion - let mut completer = - FileCompletion::new(self.engine_state.clone()); + let mut completer = FileCompletion::new( + self.engine_state.clone(), + self.stack.clone(), + ); out = self.process_completion( &mut completer, &working_set, diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index f4af6849f5..3d12f2aea4 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -1,6 +1,10 @@ use crate::completions::{matches, CompletionOptions}; +use nu_ansi_term::Style; +use nu_engine::env_to_string; use nu_path::home_dir; +use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{engine::StateWorkingSet, Span}; +use nu_utils::get_ls_colors; use std::path::{is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP}; fn complete_rec( @@ -92,10 +96,21 @@ pub fn complete_item( partial: &str, cwd: &str, options: &CompletionOptions, -) -> Vec<(nu_protocol::Span, String)> { + engine_state: &EngineState, + stack: &Stack, +) -> Vec<(nu_protocol::Span, String, Option