From 840bd98e010ae80b8bad2ca4052167b2e7d3ec36 Mon Sep 17 00:00:00 2001 From: Naftali Goldstein <44599898+gonatz@users.noreply.github.com> Date: Tue, 23 Mar 2021 05:20:01 +0200 Subject: [PATCH] support forward slash for directory completion in Windows (#3201) While the "main" separator in Windows is the backslash, it supports the forward slash as a separator too. Add support for this so that the behavior is similar to the way Windows PowerShell handles the forward slash: it is recognized as a separator, and when using for path completion the slash is reversed. --- crates/nu-cli/src/completion/path.rs | 3 ++- crates/nu-command/src/commands/run_external.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/completion/path.rs b/crates/nu-cli/src/completion/path.rs index 670d30e65a..0d0866b959 100644 --- a/crates/nu-cli/src/completion/path.rs +++ b/crates/nu-cli/src/completion/path.rs @@ -15,7 +15,8 @@ pub struct PathSuggestion { impl PathCompleter { pub fn path_suggestions(&self, partial: &str, matcher: &dyn Matcher) -> Vec { let expanded = nu_parser::expand_ndots(partial); - let expanded = expanded.as_ref(); + let expanded = expanded.replace(std::path::is_separator, &SEP.to_string()); + let expanded: &str = expanded.as_ref(); let (base_dir_name, partial) = match expanded.rfind(SEP) { Some(pos) => expanded.split_at(pos + SEP.len_utf8()), diff --git a/crates/nu-command/src/commands/run_external.rs b/crates/nu-command/src/commands/run_external.rs index 6b231b6a2b..9f4790da62 100644 --- a/crates/nu-command/src/commands/run_external.rs +++ b/crates/nu-command/src/commands/run_external.rs @@ -143,7 +143,7 @@ async fn maybe_autocd_dir<'a>( // - the command name ends in a path separator, or // - it's not a command on the path and no arguments were given. let name = &cmd.name; - let path_name = if name.ends_with(std::path::MAIN_SEPARATOR) + let path_name = if name.ends_with(std::path::is_separator) || (cmd.args.is_empty() && PathBuf::from(name).is_dir() && dunce::canonicalize(name).is_ok()