From 783f2a93423e1b5b4297682c54bd79c1de6dc547 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Tue, 3 Oct 2023 08:14:02 +1300 Subject: [PATCH] Allow auto-cd on trailing slash (#10585) # Description This allows auto-cd (cd'ing by just typing the directory name with `cd`) to work if there's a trailing slash in the path. # User-Facing Changes This should be an improvement over previous behaviour. I don't think this clashes with any existing assumptions. # Tests + Formatting # After Submitting --- crates/nu-cli/src/repl.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index ab926b2f40..cbb48e905c 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -820,16 +820,29 @@ fn looks_like_path(orig: &str) -> bool { || orig.starts_with('~') || orig.starts_with('/') || orig.starts_with('\\') + || orig.ends_with(std::path::MAIN_SEPARATOR) } +#[cfg(windows)] #[test] fn looks_like_path_windows_drive_path_works() { - let on_windows = cfg!(windows); - assert_eq!(looks_like_path("C:"), on_windows); - assert_eq!(looks_like_path("D:\\"), on_windows); - assert_eq!(looks_like_path("E:/"), on_windows); - assert_eq!(looks_like_path("F:\\some_dir"), on_windows); - assert_eq!(looks_like_path("G:/some_dir"), on_windows); + assert!(looks_like_path("C:")); + assert!(looks_like_path("D:\\")); + assert!(looks_like_path("E:/")); + assert!(looks_like_path("F:\\some_dir")); + assert!(looks_like_path("G:/some_dir")); +} + +#[cfg(windows)] +#[test] +fn trailing_slash_looks_like_path() { + assert!(looks_like_path("foo\\")) +} + +#[cfg(not(windows))] +#[test] +fn trailing_slash_looks_like_path() { + assert!(looks_like_path("foo/")) } #[test]