Skip to content

Commit 7eac794

Browse files
committed
Windows fix
1 parent 26ef819 commit 7eac794

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

crates/shell/src/completion.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,31 @@ fn is_executable(entry: &fs::DirEntry) -> bool {
188188
}
189189

190190
fn resolve_dir_path(dir_path: &str) -> PathBuf {
191-
// Unescape the directory path to handle spaces and other special characters
192-
let unescaped = unescape_for_completion(dir_path);
191+
// On Windows, we need to distinguish between:
192+
// 1. System paths like "C:\Users\..." where backslashes are path separators
193+
// 2. User-typed paths like "some\ dir/" where backslashes are escape characters
194+
//
195+
// Windows absolute paths start with a drive letter (C:\) or UNC path (\\server\share)
196+
let is_windows_absolute = cfg!(windows)
197+
&& (dir_path.len() >= 3 && dir_path.chars().nth(1) == Some(':') || // C:\...
198+
dir_path.starts_with("\\\\")); // UNC path
199+
200+
// Only unescape user-typed relative paths to handle escaped spaces
201+
// Don't unescape Windows absolute paths - their backslashes are path separators
202+
let unescaped = if is_windows_absolute {
203+
dir_path.to_string()
204+
} else {
205+
unescape_for_completion(dir_path)
206+
};
193207

194-
if dir_path.starts_with('/') {
208+
if dir_path.starts_with('/') || is_windows_absolute {
195209
PathBuf::from(unescaped)
196210
} else if let Some(stripped) = dir_path.strip_prefix('~') {
197-
let unescaped_stripped = unescape_for_completion(stripped);
211+
let unescaped_stripped = if is_windows_absolute {
212+
stripped.to_string()
213+
} else {
214+
unescape_for_completion(stripped)
215+
};
198216
dirs::home_dir()
199217
.map(|h| {
200218
h.join(

0 commit comments

Comments
 (0)