Skip to content

Commit

Permalink
Load schemes from $XDG_STATE/yazi/schemes.toml
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Jun 14, 2024
1 parent bf134a4 commit d975cc6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions yazi-config/src/schemes/schemes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ use std::collections::HashMap;
use anyhow::Result;
use serde::{Deserialize, Deserializer};

use crate::MERGED_YAZI;

/// Schemes in configuration file.
#[derive(Debug)]
pub struct Schemes {
pub rules: Vec<Scheme>,
}

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 {
Expand Down Expand Up @@ -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<String, String>,
}

0 comments on commit d975cc6

Please sign in to comment.