From ea8fa17f6e4e6145ecad164556f289b2e274bd01 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 13 Mar 2019 12:49:07 -0700 Subject: [PATCH] add config for the mux socket path --- src/config.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6d0c6d0fc..6456211c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, } fn default_hyperlink_rules() -> Vec { @@ -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::from("org", "wez", "wezterm").ok_or_else(|| err_msg("can't find project dirs")) +} + impl Config { pub fn load() -> Result { + 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();