From 60985236c7070425c28aa0c5ce675306d06ab123 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 16 Jan 2025 14:45:14 -0500 Subject: initial --- src/path.rs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/path.rs (limited to 'src/path.rs') 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") +} -- cgit v1.2.3-freya