Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 64cede1

Browse files
Xuanwosxyazi
authored andcommittedJun 14, 2024
Load schemes from $XDG_STATE/yazi/schemes.toml
Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent cfe35cc commit 64cede1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed
 

Diff for: ‎yazi-config/src/schemes/schemes.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ use std::collections::HashMap;
33
use anyhow::Result;
44
use serde::{Deserialize, Deserializer};
55

6-
use crate::MERGED_YAZI;
7-
86
/// Schemes in configuration file.
97
#[derive(Debug)]
108
pub struct Schemes {
119
pub rules: Vec<Scheme>,
1210
}
1311

1412
impl Default for Schemes {
15-
fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() }
13+
fn default() -> Self {
14+
let schemes_path = yazi_shared::Xdg::state_dir().join("schemes.toml");
15+
// Ignore any errors, as it's fine to have an empty file.
16+
let schemes_content = std::fs::read_to_string(&schemes_path).unwrap_or_default();
17+
toml::from_str(&schemes_content).unwrap()
18+
}
1619
}
1720

1821
impl Schemes {
@@ -46,8 +49,8 @@ impl<'de> Deserialize<'de> for Schemes {
4649
/// Scheme in configuration file.
4750
#[derive(Debug, Deserialize)]
4851
pub struct Scheme {
49-
pub name: String,
52+
pub name: String,
5053
#[serde(rename = "type")]
51-
pub typ: String,
54+
pub typ: String,
5255
pub config: HashMap<String, String>,
5356
}

0 commit comments

Comments
 (0)
Please sign in to comment.