diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index 3d12f2aea4..9b5a022fd2 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -5,6 +5,7 @@ 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::ffi::OsStr; use std::path::{is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP}; fn complete_rec( @@ -112,7 +113,15 @@ pub fn complete_item( get_ls_colors(ls_colors_env_str) }); let mut original_cwd = OriginalCwd::None; - let mut components = Path::new(&partial).components().peekable(); + let mut components_vec: Vec = Path::new(&partial).components().collect(); + + // Path components that end with a single "." get normalized away, + // so if the partial path ends in a literal "." we must add it back in manually + if partial.ends_with('.') && partial.len() > 1 { + components_vec.push(Component::Normal(OsStr::new("."))); + }; + let mut components = components_vec.into_iter().peekable(); + let mut cwd = match components.peek().cloned() { Some(c @ Component::Prefix(..)) => { // windows only by definition diff --git a/crates/nu-cli/tests/completions.rs b/crates/nu-cli/tests/completions.rs index 57b0dc509f..2914ee503e 100644 --- a/crates/nu-cli/tests/completions.rs +++ b/crates/nu-cli/tests/completions.rs @@ -247,6 +247,16 @@ fn file_completions() { // Match the results match_suggestions(expected_paths, suggestions); + + // Test completions for hidden files + let target_dir = format!("ls {}/.", folder(dir.join(".hidden_folder"))); + let suggestions = completer.complete(&target_dir, target_dir.len()); + + let expected_paths: Vec = + vec![file(dir.join(".hidden_folder").join(".hidden_subfile"))]; + + // Match the results + match_suggestions(expected_paths, suggestions); } #[test] diff --git a/tests/fixtures/completions/.hidden_folder/.gitkeep b/tests/fixtures/completions/.hidden_folder/.hidden_subfile similarity index 100% rename from tests/fixtures/completions/.hidden_folder/.gitkeep rename to tests/fixtures/completions/.hidden_folder/.hidden_subfile