mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 22:33:52 +03:00
add config for the mux socket path
This commit is contained in:
parent
05c14e5bc7
commit
ea8fa17f6e
@ -3,7 +3,7 @@
|
||||
use crate::font::FontSystemSelection;
|
||||
use crate::frontend::FrontEndSelection;
|
||||
use crate::{get_shell, Command};
|
||||
use directories::UserDirs;
|
||||
use directories::{ProjectDirs, UserDirs};
|
||||
use failure::{err_msg, Error};
|
||||
use std;
|
||||
use std::ffi::OsStr;
|
||||
@ -65,6 +65,10 @@ pub struct Config {
|
||||
|
||||
#[serde(default)]
|
||||
pub front_end: FrontEndSelection,
|
||||
|
||||
/// When using the MuxServer, this specifies the path to the unix
|
||||
/// domain socket to use to communicate with the mux server.
|
||||
pub mux_server_unix_domain_socket_path: Option<String>,
|
||||
}
|
||||
|
||||
fn default_hyperlink_rules() -> Vec<hyperlink::Rule> {
|
||||
@ -102,6 +106,7 @@ impl Default for Config {
|
||||
hyperlink_rules: default_hyperlink_rules(),
|
||||
term: default_term(),
|
||||
default_prog: None,
|
||||
mux_server_unix_domain_socket_path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -283,15 +288,23 @@ pub struct StyleRule {
|
||||
pub font: TextStyle,
|
||||
}
|
||||
|
||||
fn project_dirs() -> Result<ProjectDirs, Error> {
|
||||
ProjectDirs::from("org", "wez", "wezterm").ok_or_else(|| err_msg("can't find project dirs"))
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Self, Error> {
|
||||
let project_dirs = project_dirs()?;
|
||||
let dirs = UserDirs::new().ok_or_else(|| err_msg("can't find home dir"))?;
|
||||
let home = dirs.home_dir();
|
||||
|
||||
// Note that the directories crate has methods for locating project
|
||||
// specific config directories, but only returns one of them, not
|
||||
// multiple. Not sure how feel about that.
|
||||
// multiple, so we use it for one of the paths, and fill in the fallbacks
|
||||
// manually here. This will likely result in trying the same path
|
||||
// a couple of times, but that's harmless.
|
||||
let paths = [
|
||||
project_dirs.config_dir().join("wezterm.toml"),
|
||||
home.join(".config").join("wezterm").join("wezterm.toml"),
|
||||
home.join(".wezterm.toml"),
|
||||
];
|
||||
@ -310,21 +323,31 @@ impl Config {
|
||||
|
||||
let cfg: Self = toml::from_str(&s)
|
||||
.map_err(|e| format_err!("Error parsing TOML from {}: {:?}", p.display(), e))?;
|
||||
return Ok(cfg.compute_extra_defaults());
|
||||
return Ok(cfg.compute_extra_defaults(project_dirs));
|
||||
}
|
||||
|
||||
Ok(Self::default_config())
|
||||
Ok(Self::default().compute_extra_defaults(project_dirs))
|
||||
}
|
||||
|
||||
pub fn default_config() -> Self {
|
||||
Self::default().compute_extra_defaults()
|
||||
let project_dirs = project_dirs().unwrap();
|
||||
Self::default().compute_extra_defaults(project_dirs)
|
||||
}
|
||||
|
||||
/// In some cases we need to compute expanded values based
|
||||
/// on those provided by the user. This is where we do that.
|
||||
fn compute_extra_defaults(&self) -> Self {
|
||||
fn compute_extra_defaults(&self, project_dirs: ProjectDirs) -> Self {
|
||||
let mut cfg = self.clone();
|
||||
|
||||
if cfg.mux_server_unix_domain_socket_path.is_none() {
|
||||
cfg.mux_server_unix_domain_socket_path = match project_dirs.runtime_dir() {
|
||||
Some(path) => path.join("sock"),
|
||||
None => project_dirs.data_local_dir().join("sock"),
|
||||
}
|
||||
.to_str()
|
||||
.map(str::to_owned);
|
||||
}
|
||||
|
||||
if cfg.font_rules.is_empty() {
|
||||
// Expand out some reasonable default font rules
|
||||
let bold = self.font.make_bold();
|
||||
|
Loading…
Reference in New Issue
Block a user