From 64cede1fed917da95d4596094530d86ea45a2392 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Fri, 14 Jun 2024 16:33:15 +0800 Subject: [PATCH] Load schemes from `$XDG_STATE/yazi/schemes.toml` Signed-off-by: Xuanwo --- yazi-config/src/schemes/schemes.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/yazi-config/src/schemes/schemes.rs b/yazi-config/src/schemes/schemes.rs index 841f2398b..6f235fd8a 100644 --- a/yazi-config/src/schemes/schemes.rs +++ b/yazi-config/src/schemes/schemes.rs @@ -3,8 +3,6 @@ use std::collections::HashMap; use anyhow::Result; use serde::{Deserialize, Deserializer}; -use crate::MERGED_YAZI; - /// Schemes in configuration file. #[derive(Debug)] pub struct Schemes { @@ -12,7 +10,12 @@ pub struct Schemes { } impl Default for Schemes { - fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } + fn default() -> Self { + let schemes_path = yazi_shared::Xdg::state_dir().join("schemes.toml"); + // Ignore any errors, as it's fine to have an empty file. + let schemes_content = std::fs::read_to_string(&schemes_path).unwrap_or_default(); + toml::from_str(&schemes_content).unwrap() + } } impl Schemes { @@ -46,8 +49,8 @@ impl<'de> Deserialize<'de> for Schemes { /// Scheme in configuration file. #[derive(Debug, Deserialize)] pub struct Scheme { - pub name: String, + pub name: String, #[serde(rename = "type")] - pub typ: String, + pub typ: String, pub config: HashMap, }