Better filepath completions (#485)

This commit is contained in:
JT
2021-12-13 17:46:30 +11:00
committed by GitHub
parent 1336acd34a
commit 906c0e6bca
2 changed files with 21 additions and 1 deletions

View File

@ -207,6 +207,18 @@ fn file_path_completion(
) -> Vec<(nu_protocol::Span, String)> {
use std::path::{is_separator, Path};
let partial = if let Some(s) = partial.strip_prefix('"') {
s
} else {
partial
};
let partial = if let Some(s) = partial.strip_suffix('"') {
s
} else {
partial
};
let (base_dir_name, partial) = {
// If partial is only a word we want to search in the current dir
let (base, rest) = partial.rsplit_once(is_separator).unwrap_or((".", partial));
@ -237,6 +249,10 @@ fn file_path_completion(
file_name.push(SEP);
}
if path.contains(' ') {
path = format!("\"{}\"", path);
}
Some((span, path))
} else {
None