Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a persistent command history #150

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/shell/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use std::path::PathBuf;

use anyhow::Context;
Expand Down Expand Up @@ -42,6 +43,13 @@ async fn interactive() -> anyhow::Result<()> {
let mut state = init_state();

let home = dirs::home_dir().context("Couldn't get home directory")?;
let history_file: PathBuf = [home.as_path(), Path::new(".shell_history")]
.iter()
.collect();
if Path::new(history_file.as_path()).exists() {
rl.load_history(history_file.as_path())
.context("Failed to read the command history")?;
}

let mut _prev_exit_code = 0;
loop {
Expand Down Expand Up @@ -117,6 +125,8 @@ async fn interactive() -> anyhow::Result<()> {
}
}
}
rl.save_history(history_file.as_path())
.context("Failed to write the command history")?;

Ok(())
}
Expand Down
Loading