Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/configuration/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _presenterm_ allows you to customize its behavior via a configuration file. This
custom themes, in the following directories:

* `$XDG_CONFIG_HOME/presenterm/` if that environment variable is defined, otherwise:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try setting XDG_CONFIG_HOME like the docs specify? Is that not an option?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up exporting the var from my shell rc to pretend to be Linux, but it was not intuitive as other tools simply look for their config in ~/.config.

The aim of this PR is to reduce friction with a pragmatic approach / sensible default.

* `~/.config/presenterm/` in Linux.
* `~/.config/presenterm/` in Linux or macOS.
* `~/Library/Application Support/presenterm/` in macOS.
* `~/AppData/Roaming/presenterm/config/` in Windows.

Expand Down
29 changes: 24 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn create_splash() -> String {
┌─┐┬─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐┌─┐┬─┐┌┬┐
├─┘├┬┘├┤ └─┐├┤ │││ │ ├┤ ├┬┘│││
┴ ┴└─└─┘└─┘└─┘┘└┘ ┴ └─┘┴└─┴ ┴ v{crate_version}
A terminal slideshow tool
A terminal slideshow tool
@mfontanini/presenterm
"#,
)
Expand All @@ -171,13 +171,32 @@ struct Customizations {

impl Customizations {
fn load(config_file_path: Option<PathBuf>, cwd: &Path) -> Result<Self, Box<dyn std::error::Error>> {
let get_default_config_dir = || -> Result<PathBuf, Box<dyn std::error::Error>> {
let Some(project_dirs) = ProjectDirs::from("", "", "presenterm") else {
return Ok(Default::default());
};
Ok(project_dirs.config_dir().into())
};
let configs_path: PathBuf = match env::var("XDG_CONFIG_HOME") {
Ok(path) => Path::new(&path).join("presenterm"),
Err(_) => {
let Some(project_dirs) = ProjectDirs::from("", "", "presenterm") else {
return Ok(Default::default());
};
project_dirs.config_dir().into()
#[cfg(target_os = "macos")]
if let Ok(home) = env::var("HOME") {
let xdg_path = Path::new(&home).join(".config").join("presenterm");
if xdg_path.exists() {
println!("Using Home config");
xdg_path
} else {
get_default_config_dir()?
}
} else {
get_default_config_dir()?
}

#[cfg(not(target_os = "macos"))]
{
get_default_config_dir()?
}
}
};
let themes_path = configs_path.join("themes");
Expand Down