For example, when running the following:

    crates/nu-cli/src

nushell currently parses this as an external command. Before running the command, we check to see if
it's a directory. If it is, we "auto cd" into that directory, otherwise we go through normal
external processing.

If we put a trailing slash on it though, shells typically interpret that as "user is explicitly
referencing directory". So

    crates/nu-cli/src/

should not be interpreted as "run an external command". We intercept a trailing slash in the head
position of a command in a pipeline as such, and inject a `cd` internal command.
This commit is contained in:
Jason Gedge
2020-04-26 21:22:01 -04:00
committed by GitHub
parent 80025ea684
commit 6f2ef05195
9 changed files with 223 additions and 85 deletions

View File

@ -25,7 +25,7 @@ fn automatically_change_directory() {
use nu_test_support::playground::Playground;
Playground::setup("cd_test_5_1", |dirs, sandbox| {
sandbox.within("autodir").mkdir("bar");
sandbox.mkdir("autodir");
let actual = nu!(
cwd: dirs.test(),
@ -39,6 +39,25 @@ fn automatically_change_directory() {
})
}
#[test]
fn automatically_change_directory_with_trailing_slash_and_same_name_as_command() {
use nu_test_support::playground::Playground;
Playground::setup("cd_test_5_1", |dirs, sandbox| {
sandbox.mkdir("cd");
let actual = nu!(
cwd: dirs.test(),
r#"
cd/
pwd | echo $it
"#
);
assert!(actual.ends_with("cd"));
})
}
mod it_evaluation {
use super::nu;
use nu_test_support::fs::Stub::{EmptyFile, FileWithContent, FileWithContentToBeTrimmed};