diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-04-25 18:21:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-25 17:21:52 +0000 |
| commit | 156893d774b4da5b541fdbb08428f9ec392949a0 (patch) | |
| tree | 9185d94384aa62eb6eb099ddc4ca9408df6f90d1 /atuin-common/src/utils.rs | |
| parent | Add to Cargo.toml (diff) | |
| download | atuin-156893d774b4da5b541fdbb08428f9ec392949a0.zip | |
Update docs, unify on SQLx, bugfixes (#40)
* Begin moving to sqlx for local too
* Stupid scanners should just have a nice cup of tea
Random internet shit searching for /.env or whatever
* Remove diesel and rusqlite fully
Diffstat (limited to 'atuin-common/src/utils.rs')
| -rw-r--r-- | atuin-common/src/utils.rs | 39 |
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, + ) +} |
