diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index 49f426e63c..d60df4ca01 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -29,11 +29,8 @@ impl Command for Ls { fn signature(&self) -> nu_protocol::Signature { Signature::build("ls") - .optional( - "pattern", - SyntaxShape::GlobPattern, - "the glob pattern to use", - ) + // Using a string instead of a glob pattern shape so it won't auto-expand + .optional("pattern", SyntaxShape::String, "the glob pattern to use") .switch("all", "Show hidden files", Some('a')) .switch( "long", @@ -69,18 +66,22 @@ impl Command for Ls { let ctrl_c = engine_state.ctrlc.clone(); let call_span = call.head; let cwd = current_dir(engine_state, stack)?; - let pattern_arg = call.opt::>(engine_state, stack, 0)?; + + let pattern_arg: Option> = call.opt(engine_state, stack, 0)?; let (path, p_tag, absolute_path) = match pattern_arg { Some(p) => { let p_tag = p.span; let mut p = PathBuf::from(p.item); - if p.is_dir() { + + let expanded = nu_path::expand_path_with(&p, &cwd); + if expanded.is_dir() { if permission_denied(&p) { #[cfg(unix)] let error_msg = format!( "The permissions of {:o} do not allow access for this user", - p.metadata() + expanded + .metadata() .expect( "this shouldn't be called since we already know there is a dir" ) @@ -96,7 +97,7 @@ impl Command for Ls { p_tag, )); } - if is_empty_dir(&p) { + if is_empty_dir(&expanded) { return Ok(Value::nothing(call_span).into_pipeline_data()); } p.push("*"); diff --git a/crates/nu-engine/src/glob_from.rs b/crates/nu-engine/src/glob_from.rs index 2edf511507..054ca6be26 100644 --- a/crates/nu-engine/src/glob_from.rs +++ b/crates/nu-engine/src/glob_from.rs @@ -25,11 +25,7 @@ pub fn glob_from( ShellError, > { let path = PathBuf::from(&pattern.item); - let path = if path.is_relative() { - expand_path_with(path, cwd) - } else { - path - }; + let path = expand_path_with(path, cwd); let (prefix, pattern) = if path.to_string_lossy().contains('*') { // Path is a glob pattern => do not check for existence