chore: preserve capitalization in non-error output

This commit is contained in:
iff 2024-12-10 15:29:22 +01:00
parent 0a4437f5b5
commit fb1d1956d0
2 changed files with 8 additions and 11 deletions

View file

@ -1,6 +1,6 @@
use pay_respects_utils::evals::split_command;
use pay_respects_utils::files::get_path_files;
use std::process::exit;
use std::process::{exit, Stdio};
use std::collections::HashMap;
use std::sync::mpsc::channel;
@ -248,12 +248,12 @@ pub fn get_error(shell: &str, command: &str) -> String {
std::env::remove_var("_PR_ERROR_MSG");
error_msg
} else {
command_output_threaded(shell, command)
error_output_threaded(shell, command)
};
error.split_whitespace().collect::<Vec<&str>>().join(" ")
}
pub fn command_output_threaded(shell: &str, command: &str) -> String {
pub fn error_output_threaded(shell: &str, command: &str) -> String {
let (sender, receiver) = channel();
let _shell = shell.to_owned();
@ -289,12 +289,13 @@ pub fn command_output(shell: &str, command: &str) -> String {
.arg("-c")
.arg(command)
.env("LC_ALL", "C")
.stderr(Stdio::inherit())
.output()
.expect("failed to execute process");
match output.stdout.is_empty() {
false => String::from_utf8_lossy(&output.stdout).to_lowercase(),
true => String::from_utf8_lossy(&output.stderr).to_lowercase(),
false => String::from_utf8_lossy(&output.stdout).to_string(),
true => String::from_utf8_lossy(&output.stderr).to_string(),
}
}
@ -312,14 +313,10 @@ pub fn module_output(data: &Data, module: &str) -> Option<Vec<String>> {
.env("_PR_LAST_COMMAND", last_command)
.env("_PR_ERROR_MSG", error_msg)
.env("_PR_EXECUTABLES", executables)
.stderr(std::process::Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect("failed to execute process");
if !output.stderr.is_empty() {
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
}
if output.stdout.is_empty() {
return None;
}

View file

@ -173,7 +173,7 @@ pub fn install_package(data: &mut Data, package_manager: &str, package: &str) ->
"nix" => format!("nix profile install nixpkgs#{}", package),
"pacman" => format!("pacman -S {}", package),
_ => match package_manager.ends_with("command-not-found") {
true => match package.starts_with("command ") {
true => match package.starts_with("Command ") {
false => package.to_string(),
true => {
let split = package.split_whitespace().collect::<Vec<&str>>();