mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
fix: missing privileged prefix
This commit is contained in:
parent
96ac92414b
commit
11d2e3656f
3 changed files with 22 additions and 8 deletions
|
|
@ -155,7 +155,8 @@ impl Data {
|
|||
init.split();
|
||||
init.update_error(None);
|
||||
|
||||
#[cfg(debug_assertions)] {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
eprintln!("shell: {}", init.shell);
|
||||
eprintln!("command: {}", init.command);
|
||||
eprintln!("error: {}", init.error);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
use crate::shell::Data;
|
||||
use crate::shell::PRIVILEGE_LIST;
|
||||
use colored::*;
|
||||
use pay_respects_utils::evals::split_command;
|
||||
|
||||
// to_string() is necessary here, otherwise there won't be color in the output
|
||||
#[warn(clippy::unnecessary_to_owned)]
|
||||
pub fn highlight_difference(
|
||||
shell: &str,
|
||||
suggested_command: &str,
|
||||
last_command: &str,
|
||||
) -> Option<String> {
|
||||
pub fn highlight_difference(data: &Data, suggested_command: &str) -> Option<String> {
|
||||
// let replaced_newline = suggested_command.replace('\n', r" {{newline}} ");
|
||||
let shell = &data.shell;
|
||||
let last_command = &data.command;
|
||||
let mut split_suggested_command = split_command(suggested_command);
|
||||
let split_last_command = split_command(last_command);
|
||||
|
||||
|
|
@ -60,6 +59,20 @@ pub fn highlight_difference(
|
|||
split_suggested_command[len] =
|
||||
split_suggested_command[len].clone() + "\"".red().bold().to_string().as_str();
|
||||
}
|
||||
|
||||
if let Some(sudo) = data.privilege.clone() {
|
||||
if suggested_command.contains("&&")
|
||||
|| suggested_command.contains("||")
|
||||
|| suggested_command.contains('>') {
|
||||
split_suggested_command[0] = format!("{} -c \"", shell).blue().to_string()
|
||||
+ &split_suggested_command[0];
|
||||
let len = split_suggested_command.len() - 1;
|
||||
split_suggested_command[len] =
|
||||
split_suggested_command[len].clone() + "\"".blue().to_string().as_str();
|
||||
}
|
||||
split_suggested_command.insert(0, sudo.blue().to_string());
|
||||
}
|
||||
|
||||
let highlighted = split_suggested_command.join(" ");
|
||||
|
||||
Some(highlighted.replace(" \n ", "\n"))
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ pub fn select_candidate(data: &mut Data) {
|
|||
eprintln!("candidates: {candidates:?}");
|
||||
if candidates.len() == 1 {
|
||||
let suggestion = candidates[0].to_string();
|
||||
let highlighted = highlight_difference(&data.shell, &suggestion, &data.command).unwrap();
|
||||
let highlighted = highlight_difference(data, &suggestion).unwrap();
|
||||
eprintln!("{}\n", highlighted);
|
||||
let confirm = format!("[{}]", t!("confirm-yes")).green();
|
||||
eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red());
|
||||
|
|
@ -77,7 +77,7 @@ pub fn select_candidate(data: &mut Data) {
|
|||
} else {
|
||||
let mut highlight_candidates = candidates
|
||||
.iter()
|
||||
.map(|candidate| highlight_difference(&data.shell, candidate, &data.command).unwrap())
|
||||
.map(|candidate| highlight_difference(data, candidate).unwrap())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
for candidate in highlight_candidates.iter_mut() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue