Connect applications to schemes, filetypes, and more on macOS (more to come)
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplified with dir_spec

+24 -39
+7
Cargo.lock
··· 223 223 ] 224 224 225 225 [[package]] 226 + name = "dir_spec" 227 + version = "0.5.0" 228 + source = "registry+https://github.com/rust-lang/crates.io-index" 229 + checksum = "dbe111bdda79626e929d51c9b229c8127d024abc2a99efeb48f16a0a76f7d54d" 230 + 231 + [[package]] 226 232 name = "dirs" 227 233 version = "5.0.1" 228 234 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 323 329 dependencies = [ 324 330 "core-foundation", 325 331 "core-foundation-sys", 332 + "dir_spec", 326 333 "dirs", 327 334 "eyre", 328 335 "libc",
+9 -9
infat-cli/src/main.rs
··· 3 3 eyre::{Context, Result}, 4 4 owo_colors::OwoColorize, 5 5 }; 6 - use infat_lib::{GlobalOptions, app, association, config, macos::launch_services_db}; 6 + use infat_lib::{ 7 + GlobalOptions, app, association, 8 + config::{self, config_file}, 9 + macos::launch_services_db, 10 + }; 7 11 use nerdicons_rs::icons::md::{ 8 12 RSCHART_BAR, RSCHECK, RSCONTENT_SAVE_MOVE_OUTLINE, RSFILE_DOCUMENT, RSFILE_SEARCH, RSLINK, 9 13 RSTAG, ··· 69 73 } 70 74 path.clone() 71 75 } 72 - None => config::find_config_file()?.ok_or_else(|| { 76 + None => config::config_file().ok_or_else(|| { 73 77 color_eyre::eyre::eyre!( 74 78 "No configuration file found. Use {} or place config at default location", 75 79 "--config".bright_yellow() ··· 411 415 Some(path) => path, 412 416 None => match &opts.config_path { 413 417 Some(path) => path.clone(), 414 - None => { 415 - let paths = config::get_config_paths(); 416 - paths? 417 - .first() 418 - .ok_or_else(|| color_eyre::eyre::eyre!("Could not determine config path"))? 419 - .clone() 420 - } 418 + None => config_file() 419 + .ok_or_else(|| color_eyre::eyre::eyre!("Could not determine config path"))? 420 + .clone(), 421 421 }, 422 422 }; 423 423
+1
infat-lib/Cargo.toml
··· 17 17 18 18 # System 19 19 dirs = "5.0" 20 + dir_spec = "0.5.0" 20 21 21 22 [target.'cfg(target_os = "macos")'.dependencies] 22 23 # macOS system integration
+7 -30
infat-lib/src/config.rs
··· 93 93 } 94 94 } 95 95 96 - /// Get XDG-compliant configuration file paths in order of preference 97 - pub fn get_config_paths() -> Result<Vec<std::path::PathBuf>> { 98 - let mut paths = Vec::new(); 96 + pub fn config_file() -> Option<PathBuf> { 97 + let path = dir_spec::config_home() 98 + .unwrap() 99 + .join("infat") 100 + .join("config.toml"); 99 101 100 - // User-specified configuration directory 101 - let xdg_config_dirs = std::env::var("XDG_CONFIG_HOME"); 102 - 103 - if let Ok(xdg_config) = xdg_config_dirs { 104 - paths.push( 105 - std::path::PathBuf::from(xdg_config) 106 - .join("infat") 107 - .join("config.toml"), 108 - ); 109 - } 110 - 111 - // Default configuration directory ($XDG_CONFIG_HOME or ~/Library/Application Support) 112 - if let Some(config_dir) = dirs::config_dir() { 113 - paths.push(config_dir.join("infat").join("config.toml")); 114 - } 115 - 116 - if paths.is_empty() { 117 - return Err(InfatError::Generic { message: "Couldn't derive a configuration location, please file an issue -- until it's resolved, please set XDG_CONFIG_HOME".to_string() }); 118 - } 119 - 120 - Ok(paths) 121 - } 122 - 123 - /// Find the first existing configuration file 124 - pub fn find_config_file() -> Result<Option<std::path::PathBuf>> { 125 - Ok(get_config_paths()?.into_iter().find(|path| path.exists())) 102 + path.exists().then_some(path) 126 103 } 127 104 128 105 /// Apply configuration settings 129 - pub fn apply_config(config: &Config, robust: bool) -> Result<()> { 106 + pub fn apply_config(config: &Config, robust: bool) -> Result<()> { 130 107 info!("Applying configuration settings"); 131 108 132 109 config.validate()?;