[ls, path relative-to] Fix use of ls ~ | path relative-to ~ (#5212)

* [ls] implement 1b.

> `ls ~` does not return paths relative to the current directory.

We now return `/Users/blah` instead of `../../blah`

* expand lhs and rhs on `path relative-to`

/Users/nimazzuc/projects/nushell〉'~' | path relative-to '~'
/Users/nimazzuc/projects/nushell〉'~/foo' | path relative-to '~'
foo
/Users/nimazzuc/projects/nushell〉'/Users/nimazzuc/foo' | path relative-to '~'
foo
/Users/nimazzuc/projects/nushell〉'~/foo' | path relative-to '/Users/nimazzuc'
foo

* format
This commit is contained in:
nicole mazzuca
2022-04-16 13:05:42 -07:00
committed by GitHub
parent 4d31139a44
commit 6e85b04923
5 changed files with 21 additions and 12 deletions

View File

@ -3,6 +3,7 @@ use crate::DirInfo;
use chrono::{DateTime, Local};
use nu_engine::env::current_dir;
use nu_engine::CallExt;
use nu_path::expand_to_real_path;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
@ -76,7 +77,7 @@ impl Command for Ls {
let (path, p_tag, absolute_path) = match pattern_arg {
Some(p) => {
let p_tag = p.span;
let mut p = PathBuf::from(p.item);
let mut p = expand_to_real_path(p.item);
let expanded = nu_path::expand_path_with(&p, &cwd);
if expanded.is_dir() {
@ -223,6 +224,11 @@ impl Command for Ls {
example: "ls subdir",
result: None,
},
Example {
description: "List all files with full path in the parent directory",
example: "ls -f ..",
result: None,
},
Example {
description: "List all rust files",
example: "ls *.rs",
@ -234,8 +240,8 @@ impl Command for Ls {
result: None,
},
Example {
description: "List all dirs with full path name in your home directory",
example: "ls -f ~ | where type == dir",
description: "List all dirs in your home directory",
example: "ls ~ | where type == dir",
result: None,
},
Example {