Skip to content

Commit

Permalink
Source ~/.shellrc automatically if it exists
Browse files Browse the repository at this point in the history
Fixes #95.
  • Loading branch information
certik committed Sep 30, 2024
1 parent 90d3346 commit 1b0becd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async fn interactive(state: Option<ShellState>) -> 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();
Expand All @@ -62,6 +64,18 @@ async fn interactive(state: Option<ShellState>) -> 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
Expand Down

0 comments on commit 1b0becd

Please sign in to comment.