1use serde::Deserialize;
21use std::path::PathBuf;
22
23#[derive(Debug, Clone, Default, Deserialize)]
24#[serde(rename_all = "kebab-case", default)]
25pub struct PeekConfig {
26 pub defaults: DefaultsSection,
27 pub peekd: PeekdSection,
28 pub export: ExportSection,
29}
30
31#[derive(Debug, Clone, Default, Deserialize)]
32#[serde(rename_all = "kebab-case", default)]
33pub struct DefaultsSection {
34 pub no_color: bool,
36 pub resolve: bool,
38}
39
40#[derive(Debug, Clone, Default, Deserialize)]
41#[serde(rename_all = "kebab-case", default)]
42pub struct PeekdSection {
43 pub socket_path: Option<String>,
45 pub history_dir: Option<String>,
47}
48
49#[derive(Debug, Clone, Default, Deserialize)]
50#[serde(rename_all = "kebab-case", default)]
51pub struct ExportSection {
52 pub default_format: Option<String>,
54}
55
56pub fn config_path() -> PathBuf {
59 if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") {
60 return PathBuf::from(xdg).join("peek").join("config.toml");
61 }
62 if let Ok(home) = std::env::var("HOME") {
63 return PathBuf::from(home)
64 .join(".config")
65 .join("peek")
66 .join("config.toml");
67 }
68 PathBuf::from(".config").join("peek").join("config.toml")
69}
70
71pub fn load_config() -> Option<PeekConfig> {
73 let path = config_path();
74 let raw = std::fs::read_to_string(&path).ok()?;
75 toml::from_str(&raw).ok()
76}