Skip to content

Commit

Permalink
add support to override hostname and username via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
lugoues committed Jun 12, 2023
1 parent dccdb2c commit 4fb016f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 7 additions & 4 deletions atuin-client/src/api_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::env;

use chrono::Utc;
use eyre::{bail, Result};
Expand Down Expand Up @@ -161,10 +162,12 @@ impl<'a> Client<'a> {
host: Option<String>,
deleted: HashSet<String>,
) -> Result<Vec<History>> {
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={}",
Expand Down
4 changes: 3 additions & 1 deletion atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ 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 {
Expand Down
7 changes: 5 additions & 2 deletions atuin-client/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ 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(),
Expand Down

0 comments on commit 4fb016f

Please sign in to comment.