-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconfig.rs
More file actions
52 lines (49 loc) · 1.72 KB
/
config.rs
File metadata and controls
52 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::collections::BTreeMap;
/// Plugin configuration loaded from Zellij layout
#[derive(Debug, Clone)]
pub struct Config {
/// Default layout for quick session creation with Ctrl+Enter
pub default_layout: Option<String>,
/// Separator used in session names (default: ".")
pub session_separator: String,
/// Whether you'd like resurrectable sessions to be shown in the session list
pub show_resurrectable_sessions: bool,
/// Base paths to strip from directory names when generating session names
pub base_paths: Vec<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
default_layout: None,
session_separator: ".".to_string(),
show_resurrectable_sessions: false,
base_paths: Vec::new(),
}
}
}
impl Config {
/// Create configuration from Zellij plugin configuration
pub fn from_zellij_config(config: &BTreeMap<String, String>) -> Self {
Self {
default_layout: config.get("default_layout").cloned(),
session_separator: config
.get("session_separator")
.cloned()
.unwrap_or_else(|| ".".to_string()),
show_resurrectable_sessions: config
.get("show_resurrectable_sessions")
.map(|v| v == "true")
.unwrap_or(false),
base_paths: config
.get("base_paths")
.map(|paths| {
paths
.split('|')
.map(|p| p.trim().to_string())
.filter(|p| !p.is_empty())
.collect()
})
.unwrap_or_else(Vec::new),
}
}
}