aboutsummaryrefslogtreecommitdiffstats
path: root/crates/common
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 23:00:06 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-20 23:00:06 +0200
commit2f671f196e245ac1a791c001286e401a2fab9d3a (patch)
treebe90d8f16d5c8b65c6b77ebe1359d22e9738bbf6 /crates/common
parentchore: Commit (diff)
downloadatuin-2f671f196e245ac1a791c001286e401a2fab9d3a.zip
chore: Commit
Diffstat (limited to 'crates/common')
-rw-r--r--crates/common/Cargo.toml1
-rw-r--r--crates/common/src/utils.rs18
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml
index df978c03..b79932ff 100644
--- a/crates/common/Cargo.toml
+++ b/crates/common/Cargo.toml
@@ -20,6 +20,7 @@ sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "time", "postgres"
time = { version = "0.3.47", features = [ "serde-human-readable", "macros", "local-offset", "macros", "formatting", "parsing"] }
typed-builder = "0.18.2"
uuid = { version = "1.9", features = ["v4", "v7", "serde"] }
+whoami = "2.1.0"
[dev-dependencies]
diff --git a/crates/common/src/utils.rs b/crates/common/src/utils.rs
index d6077ee7..4451140b 100644
--- a/crates/common/src/utils.rs
+++ b/crates/common/src/utils.rs
@@ -4,6 +4,24 @@ use std::path::{Path, PathBuf};
use uuid::Uuid;
+#[must_use]
+pub fn get_hostname() -> String {
+ env::var("ATUIN_HOST_NAME")
+ .unwrap_or_else(|_| whoami::hostname().unwrap_or_else(|_| "unknown-host".to_string()))
+}
+
+#[must_use]
+pub fn get_username() -> String {
+ env::var("ATUIN_HOST_USER")
+ .unwrap_or_else(|_| whoami::username().unwrap_or_else(|_| "unknown-user".to_string()))
+}
+
+/// Returns a pair of the hostname and username, separated by a colon.
+#[must_use]
+pub fn get_host_user() -> String {
+ format!("{}:{}", get_hostname(), get_username())
+}
+
pub fn uuid_v7() -> Uuid {
Uuid::now_v7()
}