use serde::Deserialize;
use std::path::PathBuf;
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct PeekConfig {
pub defaults: DefaultsSection,
pub peekd: PeekdSection,
pub export: ExportSection,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct DefaultsSection {
pub no_color: bool,
pub resolve: bool,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct PeekdSection {
pub socket_path: Option<String>,
pub history_dir: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct ExportSection {
pub default_format: Option<String>,
}
pub fn config_path() -> PathBuf {
if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") {
return PathBuf::from(xdg).join("peek").join("config.toml");
}
if let Ok(home) = std::env::var("HOME") {
return PathBuf::from(home)
.join(".config")
.join("peek")
.join("config.toml");
}
PathBuf::from(".config").join("peek").join("config.toml")
}
pub fn load_config() -> Option<PeekConfig> {
let path = config_path();
let raw = std::fs::read_to_string(&path).ok()?;
toml::from_str(&raw).ok()
}