forked from extern/nushell
Make opening a directory list its contents (#3118)
* Make opening a directory enter it. Not sure if this change is wanted, but I'm not sure what else opening a directory could mean. And I find myself accidentally using `open <dir>` to mean `enter <dir>` * Add example to open directory * Open dir should list it's contents * Update example description and fix style
This commit is contained in:
parent
c13fe83784
commit
2ace20fade
@ -74,6 +74,11 @@ documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"#
|
|||||||
example: "open file.csv --encoding iso-8859-1 | from csv",
|
example: "open file.csv --encoding iso-8859-1 | from csv",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Lists the contents of a directory (identical to `ls ../projectB`)",
|
||||||
|
example: "open ../projectB",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +104,8 @@ async fn open(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let scope = args.scope.clone();
|
let scope = args.scope.clone();
|
||||||
let cwd = PathBuf::from(args.shell_manager.path());
|
let cwd = PathBuf::from(args.shell_manager.path());
|
||||||
let shell_manager = args.shell_manager.clone();
|
let shell_manager = args.shell_manager.clone();
|
||||||
|
let name = args.call_info.name_tag.clone();
|
||||||
|
let ctrl_c = args.ctrl_c.clone();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
OpenArgs {
|
OpenArgs {
|
||||||
@ -109,6 +116,17 @@ async fn open(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
_,
|
_,
|
||||||
) = args.process().await?;
|
) = args.process().await?;
|
||||||
|
|
||||||
|
if path.is_dir() {
|
||||||
|
let args = nu_engine::shell::LsArgs {
|
||||||
|
path: Some(path),
|
||||||
|
all: false,
|
||||||
|
long: false,
|
||||||
|
short_names: false,
|
||||||
|
du: false,
|
||||||
|
};
|
||||||
|
return shell_manager.ls(args, name, ctrl_c);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Remove once Streams are supported everywhere!
|
// TODO: Remove once Streams are supported everywhere!
|
||||||
// As a short term workaround for getting AutoConvert and Bat functionality (Those don't currently support Streams)
|
// As a short term workaround for getting AutoConvert and Bat functionality (Those don't currently support Streams)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use nu_test_support::fs::Stub::EmptyFile;
|
||||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||||
use nu_test_support::playground::Playground;
|
use nu_test_support::playground::Playground;
|
||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::{nu, pipeline};
|
||||||
@ -230,3 +231,24 @@ fn errors_if_file_not_found() {
|
|||||||
expected
|
expected
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn open_dir_is_ls() {
|
||||||
|
Playground::setup("open_dir", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![
|
||||||
|
EmptyFile("yehuda.txt"),
|
||||||
|
EmptyFile("jonathan.txt"),
|
||||||
|
EmptyFile("andres.txt"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), pipeline(
|
||||||
|
r#"
|
||||||
|
open .
|
||||||
|
| count
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "3");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user