diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be7fb4..6e7caa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/src/shell.rs b/core/src/shell.rs index f2d2c65..07a9d15 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -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> { let shell = &data.shell; let executable = &data.split[0]; diff --git a/core/src/system.rs b/core/src/system.rs index d0eb126..ea843d3 100644 --- a/core/src/system.rs +++ b/core/src/system.rs @@ -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 } },