mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
fix: command-not-found uses stderr
This commit is contained in:
parent
a7a281b60e
commit
69a05ef574
3 changed files with 23 additions and 2 deletions
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Not getting `command-not-found`'s output as it goes into `stderr`
|
||||
|
||||
## [0.7.0] - 2025-04-05
|
||||
|
||||
### Breaking
|
||||
|
|
|
|||
|
|
@ -325,6 +325,21 @@ pub fn command_output(shell: &str, command: &str) -> String {
|
|||
String::from_utf8_lossy(&output.stdout).to_string()
|
||||
}
|
||||
|
||||
pub fn command_output_or_error(shell: &str, command: &str) -> String {
|
||||
let output = std::process::Command::new(shell)
|
||||
.arg("-c")
|
||||
.arg(command)
|
||||
.env("LC_ALL", "C")
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
|
||||
if !output.stdout.is_empty() {
|
||||
String::from_utf8_lossy(&output.stdout).to_string()
|
||||
} else {
|
||||
String::from_utf8_lossy(&output.stderr).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn module_output(data: &Data, module: &str) -> Option<Vec<String>> {
|
||||
let shell = &data.shell;
|
||||
let executable = &data.split[0];
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::shell::command_output_or_error;
|
||||
use crate::shell::{command_output, elevate, Data};
|
||||
use colored::Colorize;
|
||||
use std::io::stderr;
|
||||
|
|
@ -152,7 +153,8 @@ pub fn get_packages(
|
|||
}
|
||||
_ => match package_manager.ends_with("command-not-found") {
|
||||
true => {
|
||||
let result = command_output(shell, &format!("{} {}", package_manager, executable));
|
||||
let result =
|
||||
command_output_or_error(shell, &format!("{} {}", package_manager, executable));
|
||||
if result.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -167,7 +169,7 @@ pub fn get_packages(
|
|||
None
|
||||
}
|
||||
false => {
|
||||
eprintln!("{} Unsupported package manager", ":pay-respects".yellow());
|
||||
eprintln!("{} Unsupported package manager", "pay-respects:".yellow());
|
||||
None
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue