Skip to content

Commit

Permalink
Completions: add support for doas as for sudo (nushell#10256)
Browse files Browse the repository at this point in the history
# Description

Fixes nushell#2047 but for the `doas` command the same way as in nushell#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 <[email protected]>
  • Loading branch information
ZerdoX-x and sholderbach authored Sep 28, 2023
1 parent d1dc610 commit 80220b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/.typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Plasticos = "Plasticos"
IIF = "IIF"
numer = "numer"
ratatui = "ratatui"
doas = "doas"
2 changes: 1 addition & 1 deletion crates/nu-cli/src/completions/command_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion crates/nu-cli/src/completions/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 80220b7

Please sign in to comment.