Skip to content

Commit

Permalink
move the config file to the std XDG .config folder
Browse files Browse the repository at this point in the history
it's not standard on mac but very widely used anyway
  • Loading branch information
seapagan committed Aug 29, 2024
1 parent 0b9f584 commit 5d35e4b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 0 additions & 8 deletions config.toml

This file was deleted.

17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 5d35e4b

Please sign in to comment.