diff options
author | Freya Murphy <freya@freyacat.org> | 2025-01-16 14:45:14 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-01-16 14:45:14 -0500 |
commit | 60985236c7070425c28aa0c5ce675306d06ab123 (patch) | |
tree | 7448aef5dadf19d4504151ebc370f9e20757ef10 /src/path.rs | |
download | iris-60985236c7070425c28aa0c5ce675306d06ab123.tar.gz iris-60985236c7070425c28aa0c5ce675306d06ab123.tar.bz2 iris-60985236c7070425c28aa0c5ce675306d06ab123.zip |
Diffstat (limited to 'src/path.rs')
-rw-r--r-- | src/path.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/path.rs b/src/path.rs new file mode 100644 index 0000000..b7fdf91 --- /dev/null +++ b/src/path.rs @@ -0,0 +1,69 @@ +//! Directory and file paths used by iris. + +use std::path::PathBuf; + +/// Root of the data directory +fn base_config_dir() -> PathBuf { + dirs::config_local_dir().expect("could not locate config directory") +} + +/// Root of the config directory +fn base_data_dir() -> PathBuf { + dirs::data_local_dir().expect("could not locate data directory") +} + +/// Path to the current diectort +pub fn current_dir() -> PathBuf { + std::env::current_dir().expect("could not locate current directory") +} + +/// Path to iris's config directory. +/// +/// This is the directory where iris will look and save it's config files. +pub fn config_dir() -> PathBuf { + base_config_dir().join("iris") +} + +/// Default path to iris's plugin file +pub fn default_plugin_file() -> PathBuf { + config_dir().join("iris.toml") +} + +/// Path to iris's plugin file +pub fn plugin_file() -> PathBuf { + [current_dir(), config_dir()] + .into_iter() + .map(|dir| dir.join("iris.toml")) + .find(|path| path.exists()) + .unwrap_or_else(default_plugin_file) +} + +/// Path to iris's lock file +pub fn lock_file() -> PathBuf { + plugin_file().with_file_name("iris.lock") +} + +/// Path to iris's data directory. +pub fn data_dir() -> PathBuf { + base_data_dir().join("iris") +} + +/// Path to iris's plugin directory. +/// +/// This is where each checkout for each plugin repository will be saved. +pub fn plugin_dir() -> PathBuf { + data_dir().join("plugins") +} + +/// Path to iris's transaction lock file. +/// +/// The transaction lock ensures that only one process is operating on iris's +/// data directory at a time. +pub fn transaction_lock_file() -> PathBuf { + data_dir().join("lock") +} + +/// Destination path for iris's vim autoload file. +pub fn autoload_file() -> PathBuf { + base_data_dir().join("nvim/site/autoload/iris.vim") +} |