diff options
-rw-r--r-- | atuin-client/src/database.rs | 5 | ||||
-rw-r--r-- | atuin-client/src/settings.rs | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index c4a9ddc3..0b145ca4 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -16,13 +16,14 @@ use sqlx::{ use super::{ history::History, ordering, - settings::{FilterMode, SearchMode}, + settings::{FilterMode, SearchMode, Settings}, }; pub struct Context { pub session: String, pub cwd: String, pub hostname: String, + pub host_id: String, } #[derive(Default, Clone)] @@ -45,11 +46,13 @@ pub fn current_context() -> Context { }; let hostname = format!("{}:{}", whoami::hostname(), whoami::username()); let cwd = utils::get_current_dir(); + let host_id = Settings::host_id().expect("failed to load host ID"); Context { session, hostname, cwd, + host_id, } } diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index 0a723fb2..f7731ab1 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -17,6 +17,7 @@ pub const HISTORY_PAGE_SIZE: i64 = 100; pub const LAST_SYNC_FILENAME: &str = "last_sync_time"; pub const LAST_VERSION_CHECK_FILENAME: &str = "last_version_check_time"; pub const LATEST_VERSION_FILENAME: &str = "latest_version"; +pub const HOST_ID_FILENAME: &str = "host_id"; #[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq)] pub enum SearchMode { @@ -222,6 +223,21 @@ impl Settings { Settings::load_time_from_file(LAST_VERSION_CHECK_FILENAME) } + pub fn host_id() -> Option<String> { + let id = Settings::read_from_data_dir(HOST_ID_FILENAME); + + if id.is_some() { + return id; + } + + let uuid = atuin_common::utils::uuid_v7(); + + Settings::save_to_data_dir(HOST_ID_FILENAME, uuid.as_simple().to_string().as_ref()) + .expect("Could not write host ID to data dir"); + + Some(uuid.as_simple().to_string()) + } + pub fn should_sync(&self) -> Result<bool> { if !self.auto_sync || !PathBuf::from(self.session_path.as_str()).exists() { return Ok(false); |