mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 18:03:51 +01:00
fixed the bug ~ | path type
return empty string (#9853)
- this PR should close #9849 - fixes #9849
This commit is contained in:
parent
e16ce1df36
commit
28ed21864d
@ -1,5 +1,6 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use nu_path::expand_tilde;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{EngineState, Stack};
|
use nu_protocol::engine::{EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
@ -78,7 +79,12 @@ If nothing is found, an empty string will be returned."#
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn r#type(path: &Path, span: Span, _: &Arguments) -> Value {
|
fn r#type(path: &Path, span: Span, _: &Arguments) -> Value {
|
||||||
let meta = std::fs::symlink_metadata(path);
|
let meta = if path.starts_with("~") {
|
||||||
|
let p = expand_tilde(path);
|
||||||
|
std::fs::symlink_metadata(p)
|
||||||
|
} else {
|
||||||
|
std::fs::symlink_metadata(path)
|
||||||
|
};
|
||||||
|
|
||||||
Value::string(
|
Value::string(
|
||||||
match &meta {
|
match &meta {
|
||||||
|
@ -50,5 +50,14 @@ fn returns_type_of_existing_directory() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "file");
|
assert_eq!(actual.out, "file");
|
||||||
|
|
||||||
|
let actual = nu!(pipeline(
|
||||||
|
r#"
|
||||||
|
echo "~"
|
||||||
|
| path type
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "dir");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user