summaryrefslogtreecommitdiffstats
path: root/atuin-common/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-common/src/utils.rs')
-rw-r--r--atuin-common/src/utils.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs
index ac5738b3..96a3a1dc 100644
--- a/atuin-common/src/utils.rs
+++ b/atuin-common/src/utils.rs
@@ -1,3 +1,5 @@
+use std::path::PathBuf;
+
use crypto::digest::Digest;
use crypto::sha2::Sha256;
use sodiumoxide::crypto::pwhash::argon2id13;
@@ -27,3 +29,40 @@ pub fn hash_str(string: &str) -> String {
pub fn uuid_v4() -> String {
Uuid::new_v4().to_simple().to_string()
}
+
+pub fn config_dir() -> PathBuf {
+ // TODO: more reliable, more tested
+ // I don't want to use ProjectDirs, it puts config in awkward places on
+ // mac. Data too. Seems to be more intended for GUI apps.
+ let home = std::env::var("HOME").expect("$HOME not found");
+ let home = PathBuf::from(home);
+
+ std::env::var("XDG_CONFIG_HOME").map_or_else(
+ |_| {
+ let mut config = home.clone();
+ config.push(".config");
+ config.push("atuin");
+ config
+ },
+ PathBuf::from,
+ )
+}
+
+pub fn data_dir() -> PathBuf {
+ // TODO: more reliable, more tested
+ // I don't want to use ProjectDirs, it puts config in awkward places on
+ // mac. Data too. Seems to be more intended for GUI apps.
+ let home = std::env::var("HOME").expect("$HOME not found");
+ let home = PathBuf::from(home);
+
+ std::env::var("XDG_DATA_HOME").map_or_else(
+ |_| {
+ let mut data = home.clone();
+ data.push(".local");
+ data.push("share");
+ data.push("atuin");
+ data
+ },
+ PathBuf::from,
+ )
+}