From a6da5340e7f034ca66c4130d0be6799d59eb19c3 Mon Sep 17 00:00:00 2001 From: Peter Brunner Date: Mon, 12 Jun 2023 12:58:46 -0400 Subject: [PATCH] add support to override hostname and username via env var (#1041) --- atuin-client/src/api_client.rs | 12 ++++++++---- atuin-client/src/database.rs | 6 +++++- atuin-client/src/history.rs | 9 +++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index 5ea84b9d..2510d197 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::collections::HashSet; +use std::env; use chrono::Utc; use eyre::{bail, Result}; @@ -161,10 +162,13 @@ impl<'a> Client<'a> { host: Option, deleted: HashSet, ) -> Result> { - let host = match host { - None => hash_str(&format!("{}:{}", whoami::hostname(), whoami::username())), - Some(h) => h, - }; + let host = host.unwrap_or_else(|| { + hash_str(&format!( + "{}:{}", + env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()), + env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()) + )) + }); let url = format!( "{}/sync/history?sync_ts={}&history_ts={}&host={}", diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index c4a9ddc3..f7c063ce 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -43,7 +43,11 @@ pub fn current_context() -> Context { eprintln!("ERROR: Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell."); std::process::exit(1); }; - let hostname = format!("{}:{}", whoami::hostname(), whoami::username()); + let hostname = format!( + "{}:{}", + env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()), + env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()) + ); let cwd = utils::get_current_dir(); Context { diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs index bb50a02a..05bfbf7f 100644 --- a/atuin-client/src/history.rs +++ b/atuin-client/src/history.rs @@ -49,8 +49,13 @@ impl History { let session = session .or_else(|| env::var("ATUIN_SESSION").ok()) .unwrap_or_else(|| uuid_v7().as_simple().to_string()); - let hostname = - hostname.unwrap_or_else(|| format!("{}:{}", whoami::hostname(), whoami::username())); + let hostname = hostname.unwrap_or_else(|| { + format!( + "{}:{}", + env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()), + env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username()) + ) + }); Self { id: uuid_v7().as_simple().to_string(),