feat: support doas

This commit is contained in:
iff 2023-07-31 01:58:37 +02:00
parent 6bd55fb316
commit ad0eaa17fc
4 changed files with 46 additions and 18 deletions

View file

@ -92,22 +92,28 @@ pub fn confirm_correction(shell: &str, command: &str, last_command: &str) {
println!("Press enter to execute the corrected command. Or press Ctrl+C to exit.");
std::io::stdin().read_line(&mut String::new()).unwrap();
if command.starts_with("sudo") {
std::process::Command::new("sudo")
.arg(shell)
.arg("-c")
.arg(command)
.spawn()
.expect("failed to execute process")
.wait()
.expect("failed to wait on process");
} else {
std::process::Command::new(shell)
.arg("-c")
.arg(command)
.spawn()
.expect("failed to execute process")
.wait()
.expect("failed to wait on process");
let privilege = Vec::from(["sudo", "doas"]);
for p in privilege {
if command.starts_with(p){
let command = command.replace(p, "");
std::process::Command::new(p)
.arg(shell)
.arg("-c")
.arg(command)
.spawn()
.expect("failed to execute process")
.wait()
.expect("failed to wait on process");
return;
}
}
std::process::Command::new(shell)
.arg("-c")
.arg(command)
.spawn()
.expect("failed to execute process")
.wait()
.expect("failed to wait on process");
}