mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
Better filepath completions (#485)
This commit is contained in:
parent
1336acd34a
commit
906c0e6bca
2 changed files with 21 additions and 1 deletions
|
@ -207,6 +207,18 @@ fn file_path_completion(
|
||||||
) -> Vec<(nu_protocol::Span, String)> {
|
) -> Vec<(nu_protocol::Span, String)> {
|
||||||
use std::path::{is_separator, Path};
|
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) = {
|
let (base_dir_name, partial) = {
|
||||||
// If partial is only a word we want to search in the current dir
|
// 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));
|
let (base, rest) = partial.rsplit_once(is_separator).unwrap_or((".", partial));
|
||||||
|
@ -237,6 +249,10 @@ fn file_path_completion(
|
||||||
file_name.push(SEP);
|
file_name.push(SEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if path.contains(' ') {
|
||||||
|
path = format!("\"{}\"", path);
|
||||||
|
}
|
||||||
|
|
||||||
Some((span, path))
|
Some((span, path))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -57,10 +57,14 @@ impl Command for External {
|
||||||
|
|
||||||
// Check if this is a single call to a directory, if so auto-cd
|
// Check if this is a single call to a directory, if so auto-cd
|
||||||
let path = nu_path::expand_path(&name.item);
|
let path = nu_path::expand_path(&name.item);
|
||||||
|
let orig = name.item.clone();
|
||||||
name.item = path.to_string_lossy().to_string();
|
name.item = path.to_string_lossy().to_string();
|
||||||
|
|
||||||
let path = Path::new(&name.item);
|
let path = Path::new(&name.item);
|
||||||
if (name.item.starts_with('.') || name.item.starts_with('/') || name.item.starts_with('\\'))
|
if (orig.starts_with('.')
|
||||||
|
|| orig.starts_with('~')
|
||||||
|
|| orig.starts_with('/')
|
||||||
|
|| orig.starts_with('\\'))
|
||||||
&& path.is_dir()
|
&& path.is_dir()
|
||||||
&& args.is_empty()
|
&& args.is_empty()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue