mirror of
https://github.com/nushell/nushell.git
synced 2025-02-02 11:39:55 +01:00
add requoting for completions (#2129)
This commit is contained in:
parent
32f18536e1
commit
28be39494c
@ -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<String> {
|
||||
@ -797,3 +797,30 @@ fn is_hidden_dir(dir: impl AsRef<Path>) -> bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn requote(
|
||||
completions: Result<(usize, Vec<rustyline::completion::Pair>), rustyline::error::ReadlineError>,
|
||||
) -> Result<(usize, Vec<rustyline::completion::Pair>), 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),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user