mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 06:58:36 +02:00
[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:
@ -1,6 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use nu_engine::CallExt;
|
||||
use nu_path::expand_to_real_path;
|
||||
use nu_protocol::{
|
||||
engine::Command, Example, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
|
||||
};
|
||||
@ -114,7 +115,9 @@ path."#
|
||||
}
|
||||
|
||||
fn relative_to(path: &Path, span: Span, args: &Arguments) -> Value {
|
||||
match path.strip_prefix(Path::new(&args.path.item)) {
|
||||
let lhs = expand_to_real_path(path);
|
||||
let rhs = expand_to_real_path(&args.path.item);
|
||||
match lhs.strip_prefix(&rhs) {
|
||||
Ok(p) => Value::string(p.to_string_lossy(), span),
|
||||
Err(e) => Value::Error {
|
||||
error: ShellError::CantConvert(e.to_string(), "string".into(), span),
|
||||
|
Reference in New Issue
Block a user