From 57ce6a7c666bca94fc962732fbd0cd2d02308848 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Tue, 14 Mar 2023 22:31:07 -0700 Subject: [PATCH] Fix ls behaviour when directory is empty (#8439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this PR, `ls` would return `nothing` in an empty directory. After this PR, it returns an empty `List`. This makes the behaviour of `ls` more consistent and easier to reason about (IMO). This was prompted by a user noticing that `ls | where size == 0KB and type == file` breaks when run in an empty directory: ``` × Input type not supported. ╭─[entry #12:1:1] 1 │ ls | where size == 0KB and type == file · ─┬ ──┬── · │ ╰── only list, binary, raw data or range input data is supported · ╰── input type: nothing ╰──── ``` If people agree with this change, let's wait until after the 0.77 release so we have a bit more time to test it. --- crates/nu-command/src/filesystem/ls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index 4aabe7cabc..02dc35dde4 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -129,7 +129,7 @@ impl Command for Ls { )); } if is_empty_dir(&expanded) { - return Ok(Value::nothing(call_span).into_pipeline_data()); + return Ok(Value::list(vec![], call_span).into_pipeline_data()); } p.push("*"); } @@ -141,7 +141,7 @@ impl Command for Ls { if directory { (PathBuf::from("."), call_span, false) } else if is_empty_dir(current_dir(engine_state, stack)?) { - return Ok(Value::nothing(call_span).into_pipeline_data()); + return Ok(Value::list(vec![], call_span).into_pipeline_data()); } else { (PathBuf::from("./*"), call_span, false) }