Completions: add support for doas as for sudo (#10256)

# Description

Fixes #2047 but for the `doas` command the same way as in #8094

# User-Facing Changes
No breaking changes. If people not using `doas`, no difference at all.

# Tests
I have not added any tests since its using same logic as for "sudo". I
guess if something would go wrong in this part, sudo tests will cover
it?

# Additional context
As a nushell user I could not find a way to implement custom completion
for a "sudo like command". Since I can see `sudo` being hardcoded in
sources, this is what I propose.

~~Also I have almost zero knowledge of rust and this is definitely not
the clean way yet~~

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Mark Lansky 2023-09-28 13:29:57 +00:00 committed by GitHub
parent d1dc610769
commit 80220b722b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

1
.github/.typos.toml vendored
View File

@ -11,3 +11,4 @@ Plasticos = "Plasticos"
IIF = "IIF"
numer = "numer"
ratatui = "ratatui"
doas = "doas"

View File

@ -234,7 +234,7 @@ pub fn is_passthrough_command(working_set_file_contents: &[(Vec<u8>, usize, usiz
let cur_pos = find_non_whitespace_index(contents, last_pipe_pos);
let result = match contents.get(cur_pos..) {
Some(contents) => contents.starts_with(b"sudo "),
Some(contents) => contents.starts_with(b"sudo ") || contents.starts_with(b"doas "),
None => false,
};
if result {

View File

@ -136,7 +136,9 @@ impl NuCompleter {
for (flat_idx, flat) in flattened.iter().enumerate() {
let is_passthrough_command = spans
.first()
.filter(|content| content.as_str() == "sudo")
.filter(|content| {
content.as_str() == "sudo" || content.as_str() == "doas"
})
.is_some();
// Read the current spam to string
let current_span = working_set.get_span_contents(flat.0).to_vec();