diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-02-13 20:21:49 +0000 |
|---|---|---|
| committer | Ellie Huxtable <e@elm.sh> | 2021-02-13 20:24:22 +0000 |
| commit | 440c4fc2335d5286d14367e39c99bb4946efe9e3 (patch) | |
| tree | 766f33c9c6b87998f22bc146fe7361e798b377df /src/local/history.rs | |
| parent | Implement history import (diff) | |
| download | atuin-440c4fc2335d5286d14367e39c99bb4946efe9e3.zip | |
Add sessions
Diffstat (limited to 'src/local/history.rs')
| -rw-r--r-- | src/local/history.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/local/history.rs b/src/local/history.rs index 00109621..bb8b9123 100644 --- a/src/local/history.rs +++ b/src/local/history.rs @@ -1,4 +1,6 @@ -use chrono; +use std::env; + +use hostname; use uuid::Uuid; #[derive(Debug)] @@ -9,10 +11,32 @@ pub struct History { pub exit: i64, pub command: String, pub cwd: String, + pub session: String, + pub hostname: String, } impl History { - pub fn new(timestamp: i64, command: String, cwd: String, exit: i64, duration: i64) -> History { + pub fn new( + timestamp: i64, + command: String, + cwd: String, + exit: i64, + duration: i64, + session: Option<String>, + hostname: Option<String>, + ) -> History { + // get the current session or just generate a random string + let env_session = + env::var("ATUIN_SESSION").unwrap_or(Uuid::new_v4().to_simple().to_string()); + + // best attempt at getting the current hostname, or just unknown + let os_hostname = hostname::get().unwrap(); + let os_hostname = os_hostname.to_str().unwrap(); + let os_hostname = String::from(os_hostname); + + let session = session.unwrap_or(env_session); + let hostname = hostname.unwrap_or(os_hostname); + History { id: Uuid::new_v4().to_simple().to_string(), timestamp, @@ -20,6 +44,8 @@ impl History { cwd, exit, duration, + session, + hostname, } } } |
