Skip to content

Commit

Permalink
add additional configuration directories
Browse files Browse the repository at this point in the history
 - in order of precedence:
   - $JOSHUTO_CONFIG_DIR
   - $XDG_CONFIG_HOME/joshuto
   - $HOME/.config/joshuto
  • Loading branch information
kamiyaa committed May 31, 2021
1 parent 7ef22c2 commit 10f2eed
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,32 @@ const PREVIEW_FILE: &str = "preview.toml";
lazy_static! {
// dynamically builds the config hierarchy
static ref CONFIG_HIERARCHY: Vec<PathBuf> = {
let mut temp = vec![];
match xdg::BaseDirectories::with_prefix(PROGRAM_NAME) {
Ok(dirs) => temp.push(dirs.get_config_home()),
Err(e) => eprintln!("{}", e),
};
let mut config_dirs = vec![];

if let Ok(p) = std::env::var("JOSHUTO_CONFIG_HOME") {
let p = PathBuf::from(p);
if p.is_dir() {
config_dirs.push(p);
}
}

if let Ok(dirs) = xdg::BaseDirectories::with_prefix(PROGRAM_NAME) {
config_dirs.push(dirs.get_config_home());
}

if let Ok(p) = std::env::var("HOME") {
let mut p = PathBuf::from(p);
p.push(".config/joshuto");
if p.is_dir() {
config_dirs.push(p);
}
}

// adds the default config files to the config hierarchy if running through cargo
if cfg!(debug_assertions) {
temp.push(PathBuf::from("./config"));
config_dirs.push(PathBuf::from("./config"));
}
temp
config_dirs
};
static ref THEME_T: AppTheme = AppTheme::get_config(THEME_FILE);
static ref MIMETYPE_T: AppMimetypeRegistry = AppMimetypeRegistry::get_config(MIMETYPE_FILE);
Expand Down Expand Up @@ -80,9 +96,8 @@ fn run_joshuto(args: Args) -> Result<(), JoshutoError> {
let config = AppConfig::get_config(CONFIG_FILE);
let keymap = AppKeyMapping::get_config(KEYMAP_FILE);

let mut context = AppContext::new(config);

{
let mut context = AppContext::new(config);
let mut backend: ui::TuiBackend = ui::TuiBackend::new()?;
run(&mut backend, &mut context, keymap)?;
}
Expand Down

0 comments on commit 10f2eed

Please sign in to comment.