diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-04-13 19:14:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-13 19:14:07 +0100 |
| commit | 5751463942cc91f1f1ffaf6e2ac633d7a0085f25 (patch) | |
| tree | f7b5b9a4702c4c3ef29aa60d36612f61ffeae052 /src/command/history.rs | |
| parent | Update config (diff) | |
| download | atuin-5751463942cc91f1f1ffaf6e2ac633d7a0085f25.zip | |
Add history sync, resolves #13 (#31)
* Add encryption
* Add login and register command
* Add count endpoint
* Write initial sync push
* Add single sync command
Confirmed working for one client only
* Automatically sync on a configurable frequency
* Add key command, key arg to login
* Only load session if it exists
* Use sync and history timestamps for download
* Bind other key code
Seems like some systems have this code for up arrow? I'm not sure why,
and it's not an easy one to google.
* Simplify upload
* Try and fix download sync loop
* Change sync order to avoid uploading what we just downloaded
* Multiline import fix
* Fix time parsing
* Fix importing history with no time
* Add hostname to sync
* Use hostname to filter sync
* Fixes
* Add binding
* Stuff from yesterday
* Set cursor modes
* Make clippy happy
* Bump version
Diffstat (limited to 'src/command/history.rs')
| -rw-r--r-- | src/command/history.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/command/history.rs b/src/command/history.rs index 05aed4b9..3b4a717c 100644 --- a/src/command/history.rs +++ b/src/command/history.rs @@ -1,10 +1,13 @@ use std::env; use eyre::Result; +use fork::{fork, Fork}; use structopt::StructOpt; use crate::local::database::Database; use crate::local::history::History; +use crate::local::sync; +use crate::settings::Settings; #[derive(StructOpt)] pub enum Cmd { @@ -50,21 +53,13 @@ fn print_list(h: &[History]) { } impl Cmd { - pub fn run(&self, db: &mut impl Database) -> Result<()> { + pub fn run(&self, settings: &Settings, db: &mut impl Database) -> Result<()> { match self { Self::Start { command: words } => { let command = words.join(" "); let cwd = env::current_dir()?.display().to_string(); - let h = History::new( - chrono::Utc::now().timestamp_nanos(), - command, - cwd, - -1, - -1, - None, - None, - ); + let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None); // print the ID // we use this as the key for calling end @@ -76,10 +71,23 @@ impl Cmd { Self::End { id, exit } => { let mut h = db.load(id)?; h.exit = *exit; - h.duration = chrono::Utc::now().timestamp_nanos() - h.timestamp; + h.duration = chrono::Utc::now().timestamp_nanos() - h.timestamp.timestamp_nanos(); db.update(&h)?; + if settings.local.should_sync()? { + match fork() { + Ok(Fork::Parent(child)) => { + debug!("launched sync background process with PID {}", child); + } + Ok(Fork::Child) => { + debug!("running periodic background sync"); + sync::sync(settings, false, db)?; + } + Err(_) => println!("Fork failed"), + } + } + Ok(()) } |
