From 80220b722b4dddaa1c3796a0ea8f43a291cba4c9 Mon Sep 17 00:00:00 2001 From: Mark Lansky <49815452+ZerdoX-x@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:29:57 +0000 Subject: [PATCH] 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 --- .github/.typos.toml | 1 + crates/nu-cli/src/completions/command_completions.rs | 2 +- crates/nu-cli/src/completions/completer.rs | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/.typos.toml b/.github/.typos.toml index 66420ee68a27..6d7b96d42293 100644 --- a/.github/.typos.toml +++ b/.github/.typos.toml @@ -11,3 +11,4 @@ Plasticos = "Plasticos" IIF = "IIF" numer = "numer" ratatui = "ratatui" +doas = "doas" diff --git a/crates/nu-cli/src/completions/command_completions.rs b/crates/nu-cli/src/completions/command_completions.rs index c99c00985e5a..371627a9ef32 100644 --- a/crates/nu-cli/src/completions/command_completions.rs +++ b/crates/nu-cli/src/completions/command_completions.rs @@ -234,7 +234,7 @@ pub fn is_passthrough_command(working_set_file_contents: &[(Vec, 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 { diff --git a/crates/nu-cli/src/completions/completer.rs b/crates/nu-cli/src/completions/completer.rs index 66afe3999a4f..cbd89b3bcf8b 100644 --- a/crates/nu-cli/src/completions/completer.rs +++ b/crates/nu-cli/src/completions/completer.rs @@ -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();