2021-02-13 13:21:49 -07:00
|
|
|
use std::env;
|
|
|
|
|
2021-02-13 10:02:52 -07:00
|
|
|
use uuid::Uuid;
|
2020-10-04 17:59:28 -06:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct History {
|
2021-02-13 10:02:52 -07:00
|
|
|
pub id: String,
|
2020-10-04 17:59:28 -06:00
|
|
|
pub timestamp: i64,
|
2021-02-13 10:02:52 -07:00
|
|
|
pub duration: i64,
|
|
|
|
pub exit: i64,
|
2020-10-04 17:59:28 -06:00
|
|
|
pub command: String,
|
|
|
|
pub cwd: String,
|
2021-02-13 13:21:49 -07:00
|
|
|
pub session: String,
|
|
|
|
pub hostname: String,
|
2020-10-04 17:59:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl History {
|
2021-02-13 13:21:49 -07:00
|
|
|
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);
|
|
|
|
|
2020-10-04 17:59:28 -06:00
|
|
|
History {
|
2021-02-13 10:02:52 -07:00
|
|
|
id: Uuid::new_v4().to_simple().to_string(),
|
2021-02-13 12:37:00 -07:00
|
|
|
timestamp,
|
2020-10-05 10:20:48 -06:00
|
|
|
command,
|
|
|
|
cwd,
|
2021-02-13 10:02:52 -07:00
|
|
|
exit,
|
|
|
|
duration,
|
2021-02-13 13:21:49 -07:00
|
|
|
session,
|
|
|
|
hostname,
|
2020-10-04 17:59:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|