2023-07-31 14:27:44 +02:00
|
|
|
use colored::Colorize;
|
|
|
|
|
|
2023-07-31 14:12:45 +02:00
|
|
|
mod args;
|
2023-07-30 18:40:18 +02:00
|
|
|
mod corrections;
|
|
|
|
|
mod shell;
|
|
|
|
|
mod style;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
std::env::set_var("LC_ALL", "C");
|
2023-07-31 14:12:45 +02:00
|
|
|
args::handle_args();
|
2023-07-30 18:40:18 +02:00
|
|
|
|
2023-07-31 14:12:45 +02:00
|
|
|
let shell = std::env::var("_PR_SHELL").expect(
|
|
|
|
|
"No _PR_SHELL in environment. Did you aliased the binary with the correct arguments?",
|
|
|
|
|
);
|
|
|
|
|
let last_command = shell::last_command_expanded_alias(&shell);
|
2023-07-30 23:48:04 +02:00
|
|
|
let corrected_command = corrections::correct_command(&shell, &last_command);
|
2023-07-31 01:58:37 +02:00
|
|
|
|
2023-07-31 09:24:46 +02:00
|
|
|
if let Some(corrected_command) = corrected_command {
|
2023-07-31 23:42:19 +02:00
|
|
|
if corrected_command != last_command {
|
|
|
|
|
corrections::confirm_correction(&shell, &corrected_command, &last_command);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|
2023-07-31 23:42:19 +02:00
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
"No correction found for the command: {}\n",
|
|
|
|
|
last_command.red().bold()
|
|
|
|
|
);
|
2023-07-31 23:48:14 +02:00
|
|
|
println!(
|
|
|
|
|
"If you think there should be a correction, please open an issue or send a pull request!"
|
|
|
|
|
);
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|