diff --git a/crates/nu-cli/src/shell/filesystem_shell.rs b/crates/nu-cli/src/shell/filesystem_shell.rs index dd4c02b4a..748f4089a 100644 --- a/crates/nu-cli/src/shell/filesystem_shell.rs +++ b/crates/nu-cli/src/shell/filesystem_shell.rs @@ -705,7 +705,7 @@ impl Shell for FilesystemShell { pos }; - self.completer.complete(&expanded, pos, ctx) + requote(self.completer.complete(&expanded, pos, ctx)) } fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option { @@ -797,3 +797,30 @@ fn is_hidden_dir(dir: impl AsRef) -> bool { } } } + +fn requote( + completions: Result<(usize, Vec), rustyline::error::ReadlineError>, +) -> Result<(usize, Vec), rustyline::error::ReadlineError> { + match completions { + Ok(items) => { + let mut new_items = Vec::with_capacity(items.0); + + for item in items.1 { + let unescaped = rustyline::completion::unescape(&item.replacement, Some('\\')); + let maybe_quote = if unescaped != item.replacement { + "\"" + } else { + "" + }; + + new_items.push(rustyline::completion::Pair { + display: item.display, + replacement: format!("{}{}{}", maybe_quote, unescaped, maybe_quote), + }); + } + + Ok((items.0, new_items)) + } + Err(err) => Err(err), + } +}