From b5c975f59703a030e03505b5d7797f28470833f9 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sun, 12 Sep 2021 22:56:19 +0200 Subject: [PATCH] Add `options` subcommand to `attach` fixes #688 - the `options` subcommand of `attach` functions the same, as the `options` subcommand of creating the normal session, but not every option will have an effect on reattaching, for example the `default_mode` setting would make no sense to switch. In the future it would make sense to be able to hot swap some of the options on reattach, but we are not able to do that yet, for example the `default_shell` one. Eg: ``` zellij attach options --theme ``` --- src/main.rs | 11 +++++++++-- zellij-client/src/lib.rs | 2 +- zellij-utils/src/cli.rs | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f0d00f77ac..eb3087811c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::process; use zellij_client::{os_input_output::get_client_os_input, start_client, ClientInfo}; use zellij_server::{os_input_output::get_server_os_input, start_server}; use zellij_utils::{ - cli::{CliArgs, Command, Sessions}, + cli::{CliArgs, Command, SessionCommand, Sessions}, consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, logging::*, setup::{get_default_data_dir, Setup}, @@ -46,6 +46,7 @@ pub fn main() { if let Some(Command::Sessions(Sessions::Attach { mut session_name, force, + options, })) = opts.command.clone() { if let Some(session) = session_name.as_ref() { @@ -61,16 +62,21 @@ pub fn main() { process::exit(1); } }; + let config_options = match options { + Some(SessionCommand::Options(o)) => config_options.merge(o), + None => config_options, + }; start_client( Box::new(os_input), opts, config, + config_options.clone(), ClientInfo::Attach(session_name.unwrap(), force, config_options), None, ); } else { - let (config, layout, _) = match Setup::from_options(&opts) { + let (config, layout, config_options) = match Setup::from_options(&opts) { Ok(results) => results, Err(e) => { eprintln!("{}", e); @@ -93,6 +99,7 @@ pub fn main() { Box::new(os_input), opts, config, + config_options, ClientInfo::New(session_name), layout, ); diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 7d67a01ac3..bd2c637688 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -86,6 +86,7 @@ pub fn start_client( mut os_input: Box, opts: CliArgs, config: Config, + config_options: Options, info: ClientInfo, layout: Option, ) { @@ -105,7 +106,6 @@ pub fn start_client( .unwrap(); std::env::set_var(&"ZELLIJ", "0"); - let config_options = Options::from_cli(&config.options, opts.command.clone()); let palette = config.themes.clone().map_or_else( || os_input.load_palette(), |t| { diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index 2ac0e986ba..a8dc9c0aa1 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -62,6 +62,13 @@ pub enum Command { Sessions(Sessions), } +#[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] +pub enum SessionCommand { + /// Change the behaviour of zellij + #[structopt(name = "options")] + Options(Options), +} + #[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] pub enum Sessions { /// List active sessions @@ -78,5 +85,8 @@ pub enum Sessions { /// zellij client (if any) and attach to this. #[structopt(long, short)] force: bool, + /// Change the behaviour of zellij + #[structopt(subcommand, name = "options")] + options: Option, }, }