diff --git a/Cargo.lock b/Cargo.lock index 6c7f1a4..41d8853 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -518,6 +518,7 @@ dependencies = [ "chrono", "clap", "config", + "dirs-next", "glob", "inline_colorization", "nix", diff --git a/Cargo.toml b/Cargo.toml index 7e69078..e0864dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ prettytable = "0.10.0" term_size = "0.3.2" config = "0.14.0" serde = { version = "1.0.209", features = ["derive"] } +dirs-next = "2.0.0" diff --git a/config.toml b/config.toml deleted file mode 100644 index a4eacc3..0000000 --- a/config.toml +++ /dev/null @@ -1,8 +0,0 @@ -[lsplus] -long_format = true -show_all = true -append_slash = true -dirs_first = true -human_readable = true -fuzzy_time = true -no_icons = false diff --git a/src/main.rs b/src/main.rs index 57a47c1..781989d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,20 +11,29 @@ mod cli; mod structs; mod utils; use config::{Config, File, FileFormat}; +use dirs_next::home_dir; use structs::{FileInfo, Params}; use utils::file::{check_display_name, collect_file_info}; -fn load_config(file_path: &str) -> Params { +fn load_config() -> Params { + let mut config_path = PathBuf::new(); + + // Get the home directory and construct the path + if let Some(home_dir) = home_dir() { + config_path.push(home_dir); + config_path.push(".config/lsplus/config.toml"); + } + let settings = Config::builder() - .add_source(File::new(file_path, FileFormat::Toml)) + .add_source(File::new(config_path.to_str().unwrap(), FileFormat::Toml)) .build(); match settings { Ok(config) => config.into(), // Convert Config into Params using the From trait Err(e) => { // If the error is related to the file not being found, return default Params - if e.to_string().contains("No such file or directory") { + if e.to_string().contains("not found") { Params::default() } else { eprintln!("Error loading config: {}", e); @@ -42,7 +51,7 @@ fn main() { } // Load config values - let config = load_config("config.toml"); + let config = load_config(); let params = Params { show_all: args.show_all || config.show_all,