From 1b0becdb3a9b3eb29d9b8c84a21c515adec789a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Mon, 30 Sep 2024 16:46:25 -0600 Subject: [PATCH] Source ~/.shellrc automatically if it exists Fixes #95. --- crates/shell/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index b513a6e..a830083 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -53,6 +53,8 @@ async fn interactive(state: Option) -> miette::Result<()> { let mut state = state.unwrap_or_else(init_state); let home = dirs::home_dir().ok_or(miette::miette!("Couldn't get home directory"))?; + + // Load .shell_history let history_file: PathBuf = [home.as_path(), Path::new(".shell_history")] .iter() .collect(); @@ -62,6 +64,18 @@ async fn interactive(state: Option) -> miette::Result<()> { .context("Failed to read the command history")?; } + // Load ~/.shellrc + let shellrc_file: PathBuf = [home.as_path(), Path::new(".shellrc")] + .iter() + .collect(); + if Path::new(shellrc_file.as_path()).exists() { + let line = "source '".to_owned() + shellrc_file.to_str().unwrap() + "'"; + let prev_exit_code = execute(&line, &mut state) + .await + .context("Failed to source ~/.shellrc")?; + state.set_last_command_exit_code(prev_exit_code); + } + let mut _prev_exit_code = 0; loop { // Reset cancellation flag