diff --git a/src/main.rs b/src/main.rs index eea7959..de8dad6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// pay-respect: Press F to correct your command +// pay-respects: Press F to correct your command // Copyright (C) 2023 iff // This program is free software: you can redistribute it and/or modify @@ -26,9 +26,14 @@ mod suggestions; fn main() { args::handle_args(); - let shell = std::env::var("_PR_SHELL").expect( - "No _PR_SHELL in environment. Did you aliased the binary with the correct arguments?", - ); + let shell = match std::env::var("_PR_SHELL") { + Ok(shell) => shell, + Err(_) => { + eprintln!("No _PR_SHELL in environment. Did you aliased the command with the correct argument?\n\nUse `pay-respects -h` for help"); + std::process::exit(1); + } + }; + let mut last_command = shell::last_command_expanded_alias(&shell); let mut error_msg = command_output(&shell, &last_command); loop { diff --git a/src/shell.rs b/src/shell.rs index f70f398..0b4cfde 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -41,7 +41,14 @@ pub fn command_output(shell: &str, command: &str) -> String { } fn last_command(shell: &str) -> String { - let last_command = std::env::var("_PR_LAST_COMMAND").expect("No _PR_LAST_COMMAND in environment. Did you aliased the command with the correct argument?"); + let last_command = match std::env::var("_PR_LAST_COMMAND") { + Ok(command) => command, + Err(_) => { + eprintln!("No _PR_LAST_COMMAND in environment. Did you aliased the command with the correct argument?\n\nUse `pay-respects -h` for help"); + exit(1); + } + }; + match shell { "bash" => { let first_line = last_command.lines().next().unwrap().trim();