feat: tmux session attach mode (#901)

* feat: tmux session attach mode

* feat: example config update

* feat: move the comment down to be relevant

* feat: fix tmux not attaching from non-tmux env when using create_and_switch_client

* feat: make matching on tmux modes as described in suggestions

* feat: make tmux_session_attach_mode private

* feat: remove tmux mode cli option

* feat: wrap default value in quotation marks for tmux session mode

* feat: renames for tmux session management options

* feat: try to make tmux session mode description better
This commit is contained in:
wetfloo
2024-09-17 20:06:39 +07:00
committed by GitHub
parent ad41948450
commit 21751aa8a5
4 changed files with 67 additions and 13 deletions

View File

@@ -403,6 +403,8 @@ pub struct Misc {
run_in_tmux: Option<bool>,
tmux_session_mode: Option<TmuxSessionMode>,
cleanup: Option<bool>,
notify_each_step: Option<bool>,
@@ -419,6 +421,19 @@ pub struct Misc {
log_filters: Option<Vec<String>>,
}
#[derive(Clone, Copy, Debug, Deserialize, ValueEnum)]
#[clap(rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum TmuxSessionMode {
AttachIfNotInSession,
AttachAlways,
}
pub struct TmuxConfig {
pub args: Vec<String>,
pub session_mode: TmuxSessionMode,
}
#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Lensfun {
@@ -967,6 +982,15 @@ impl Config {
.unwrap_or(false)
}
/// The preferred way to run the new tmux session.
fn tmux_session_mode(&self) -> TmuxSessionMode {
self.config_file
.misc
.as_ref()
.and_then(|misc| misc.tmux_session_mode)
.unwrap_or(TmuxSessionMode::AttachIfNotInSession)
}
/// Tell whether we should perform cleanup steps.
pub fn cleanup(&self) -> bool {
self.opt.cleanup
@@ -1024,8 +1048,16 @@ impl Config {
self.config_file.git.as_ref().and_then(|git| git.arguments.as_ref())
}
pub fn tmux_config(&self) -> Result<TmuxConfig> {
let args = self.tmux_arguments()?;
Ok(TmuxConfig {
args,
session_mode: self.tmux_session_mode(),
})
}
/// Extra Tmux arguments
pub fn tmux_arguments(&self) -> Result<Vec<String>> {
fn tmux_arguments(&self) -> Result<Vec<String>> {
let args = &self
.config_file
.misc