aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-02-18 14:11:31 -0500
committerGitHub <noreply@github.com>2023-02-18 14:11:31 -0500
commit68d78e98747a5f69fcfa9094976dc28a290e5e3c (patch)
treefedf34002ff42af730d9edbc2e93d6b58013968a
parentc77ccb67cf464abfb30d42f2ef870dc2bbf24366 (diff)
parentd4453cb44a10f9bb558fd2a5561cc5223ba36a23 (diff)
downloadrbw-68d78e98747a5f69fcfa9094976dc28a290e5e3c.tar.gz
rbw-68d78e98747a5f69fcfa9094976dc28a290e5e3c.zip
Merge pull request #93 from Hyask/skia/profile
Support multiple profiles with an environment variable
-rw-r--r--src/bin/rbw-agent/actions.rs2
-rw-r--r--src/dirs.rs23
2 files changed, 19 insertions, 6 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 87a8276..61eb74b 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -367,7 +367,7 @@ pub async fn unlock(
let password = rbw::pinentry::getpin(
&config_pinentry().await?,
"Master Password",
- "Unlock the local database",
+ &format!("Unlock the local database for '{}'", rbw::dirs::profile()),
err.as_deref(),
tty,
true,
diff --git a/src/dirs.rs b/src/dirs.rs
index 5ebeaa2..429f8bd 100644
--- a/src/dirs.rs
+++ b/src/dirs.rs
@@ -79,32 +79,45 @@ pub fn socket_file() -> std::path::PathBuf {
#[must_use]
fn config_dir() -> std::path::PathBuf {
- let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap();
+ let project_dirs =
+ directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.config_dir().to_path_buf()
}
#[must_use]
fn cache_dir() -> std::path::PathBuf {
- let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap();
+ let project_dirs =
+ directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.cache_dir().to_path_buf()
}
#[must_use]
fn data_dir() -> std::path::PathBuf {
- let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap();
+ let project_dirs =
+ directories::ProjectDirs::from("", "", &profile()).unwrap();
project_dirs.data_dir().to_path_buf()
}
#[must_use]
fn runtime_dir() -> std::path::PathBuf {
- let project_dirs = directories::ProjectDirs::from("", "", "rbw").unwrap();
+ let project_dirs =
+ directories::ProjectDirs::from("", "", &profile()).unwrap();
match project_dirs.runtime_dir() {
Some(dir) => dir.to_path_buf(),
None => format!(
- "{}/rbw-{}",
+ "{}/{}-{}",
std::env::temp_dir().to_string_lossy(),
+ &profile(),
nix::unistd::getuid().as_raw()
)
.into(),
}
}
+
+#[must_use]
+pub fn profile() -> String {
+ match std::env::var("RBW_PROFILE") {
+ Ok(profile) if !profile.is_empty() => format!("rbw-{}", profile),
+ _ => "rbw".to_string(),
+ }
+}