mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 07:35:10 +01:00
fix: extract inline environment variables
This commit is contained in:
parent
69a05ef574
commit
f452f7196f
3 changed files with 30 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Parsing command environment variables (e.g. `LANG=ja_JP.UTF-8 pacman` will work as intended)
|
||||||
- Not getting `command-not-found`'s output as it goes into `stderr`
|
- Not getting `command-not-found`'s output as it goes into `stderr`
|
||||||
|
|
||||||
## [0.7.0] - 2025-04-05
|
## [0.7.0] - 2025-04-05
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ impl Init {
|
||||||
|
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub shell: String,
|
pub shell: String,
|
||||||
|
pub env: Option<String>,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub suggest: Option<String>,
|
pub suggest: Option<String>,
|
||||||
pub candidates: Vec<String>,
|
pub candidates: Vec<String>,
|
||||||
|
|
@ -151,6 +152,7 @@ impl Data {
|
||||||
|
|
||||||
let mut init = Data {
|
let mut init = Data {
|
||||||
shell,
|
shell,
|
||||||
|
env: None,
|
||||||
command,
|
command,
|
||||||
suggest: None,
|
suggest: None,
|
||||||
candidates: vec![],
|
candidates: vec![],
|
||||||
|
|
@ -165,6 +167,7 @@ impl Data {
|
||||||
};
|
};
|
||||||
|
|
||||||
init.split();
|
init.split();
|
||||||
|
init.extract_env();
|
||||||
init.expand_command();
|
init.expand_command();
|
||||||
if init.mode != Mode::Cnf {
|
if init.mode != Mode::Cnf {
|
||||||
init.update_error(None);
|
init.update_error(None);
|
||||||
|
|
@ -174,6 +177,7 @@ impl Data {
|
||||||
{
|
{
|
||||||
eprintln!("/// data initialization");
|
eprintln!("/// data initialization");
|
||||||
eprintln!("shell: {}", init.shell);
|
eprintln!("shell: {}", init.shell);
|
||||||
|
eprintln!("env: {:?}", init.env);
|
||||||
eprintln!("command: {}", init.command);
|
eprintln!("command: {}", init.command);
|
||||||
eprintln!("error: {}", init.error);
|
eprintln!("error: {}", init.error);
|
||||||
eprintln!("modules: {:?}", init.modules);
|
eprintln!("modules: {:?}", init.modules);
|
||||||
|
|
@ -218,6 +222,21 @@ impl Data {
|
||||||
self.split = split;
|
self.split = split;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn extract_env(&mut self) {
|
||||||
|
let mut envs = vec![];
|
||||||
|
loop {
|
||||||
|
if self.split[0][1..].contains("=") {
|
||||||
|
envs.push(self.split.remove(0));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !envs.is_empty() {
|
||||||
|
self.env = Some(envs.join(" "));
|
||||||
|
self.command = self.split.join(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_error(&mut self, error: Option<String>) {
|
pub fn update_error(&mut self, error: Option<String>) {
|
||||||
if let Some(error) = error {
|
if let Some(error) = error {
|
||||||
self.error = error
|
self.error = error
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,11 @@ pub fn confirm_suggestion(data: &Data) -> Result<(), String> {
|
||||||
pub fn run_suggestion(data: &Data, command: &str) -> std::process::ExitStatus {
|
pub fn run_suggestion(data: &Data, command: &str) -> std::process::ExitStatus {
|
||||||
let shell = &data.shell;
|
let shell = &data.shell;
|
||||||
let privilege = &data.privilege;
|
let privilege = &data.privilege;
|
||||||
|
let command = if let Some(env) = &data.env {
|
||||||
|
format!("{env} {command}")
|
||||||
|
} else {
|
||||||
|
command.to_string()
|
||||||
|
};
|
||||||
match privilege {
|
match privilege {
|
||||||
Some(sudo) => std::process::Command::new(sudo)
|
Some(sudo) => std::process::Command::new(sudo)
|
||||||
.arg(shell)
|
.arg(shell)
|
||||||
|
|
@ -186,6 +191,11 @@ pub fn run_suggestion(data: &Data, command: &str) -> std::process::ExitStatus {
|
||||||
fn suggestion_err(data: &Data, command: &str) -> Result<(), String> {
|
fn suggestion_err(data: &Data, command: &str) -> Result<(), String> {
|
||||||
let shell = &data.shell;
|
let shell = &data.shell;
|
||||||
let privilege = &data.privilege;
|
let privilege = &data.privilege;
|
||||||
|
let command = if let Some(env) = &data.env {
|
||||||
|
format!("{env} {command}")
|
||||||
|
} else {
|
||||||
|
command.to_string()
|
||||||
|
};
|
||||||
let process = match privilege {
|
let process = match privilege {
|
||||||
Some(sudo) => std::process::Command::new(sudo)
|
Some(sudo) => std::process::Command::new(sudo)
|
||||||
.arg(shell)
|
.arg(shell)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue