Skip to content

Commit

Permalink
Add options subcommand to attach (#718)
Browse files Browse the repository at this point in the history
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 <session-name> options --theme <theme>
  ```
  • Loading branch information
a-kenji committed Sep 13, 2021
1 parent cfdc2ea commit 9a5a315
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -54,6 +54,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() {
Expand All @@ -62,10 +63,16 @@ pub fn main() {
session_name = Some(get_active_session());
}

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,
);
Expand All @@ -85,6 +92,7 @@ pub fn main() {
Box::new(os_input),
opts,
config,
config_options,
ClientInfo::New(session_name),
layout,
);
Expand Down
2 changes: 1 addition & 1 deletion zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub fn start_client(
mut os_input: Box<dyn ClientOsApi>,
opts: CliArgs,
config: Config,
config_options: Options,
info: ClientInfo,
layout: Option<LayoutFromYaml>,
) {
Expand All @@ -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| {
Expand Down
10 changes: 10 additions & 0 deletions zellij-utils/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SessionCommand>,
},
}

0 comments on commit 9a5a315

Please sign in to comment.