summaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/atuin-client/src/utils.rs')
-rw-r--r--crates/atuin-client/src/utils.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/atuin-client/src/utils.rs b/crates/atuin-client/src/utils.rs
new file mode 100644
index 00000000..a7c6eab0
--- /dev/null
+++ b/crates/atuin-client/src/utils.rs
@@ -0,0 +1,14 @@
+pub(crate) fn get_hostname() -> String {
+ std::env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| {
+ whoami::fallible::hostname().unwrap_or_else(|_| "unknown-host".to_string())
+ })
+}
+
+pub(crate) fn get_username() -> String {
+ std::env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username())
+}
+
+/// Returns a pair of the hostname and username, separated by a colon.
+pub(crate) fn get_host_user() -> String {
+ format!("{}:{}", get_hostname(), get_username())
+}