Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): new-tab now also looks in layout_dir for layouts #2198

Merged
merged 3 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zellij-server/src/unit/screen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,7 @@ pub fn send_cli_new_tab_action_default_params() {
let new_tab_action = CliAction::NewTab {
name: None,
layout: None,
layout_dir: None,
cwd: None,
};
send_cli_action_to_server(
Expand Down Expand Up @@ -2414,6 +2415,7 @@ pub fn send_cli_new_tab_action_with_name_and_layout() {
"{}/src/unit/fixtures/layout-with-three-panes.kdl",
env!("CARGO_MANIFEST_DIR")
))),
layout_dir: None,
cwd: None,
};
send_cli_action_to_server(
Expand Down
4 changes: 4 additions & 0 deletions zellij-utils/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ pub enum CliAction {
#[clap(short, long, value_parser)]
layout: Option<PathBuf>,

/// Default folder to look for layouts
#[clap(short, long, value_parser, requires("layout"))]
layout_dir: Option<PathBuf>,

/// Name of the new tab
#[clap(short, long, value_parser)]
name: Option<String>,
Expand Down
12 changes: 10 additions & 2 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::data::InputMode;
use crate::data::{Direction, Resize};
use crate::input::config::{ConfigError, KdlError};
use crate::input::options::OnForceClose;
use crate::setup::{find_default_config_dir, get_layout_dir};
use miette::{NamedSource, Report};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -348,14 +349,21 @@ impl Action {
Action::TabNameInput(name.as_bytes().to_vec()),
]),
CliAction::UndoRenameTab => Ok(vec![Action::UndoRenameTab]),
CliAction::NewTab { name, layout, cwd } => {
CliAction::NewTab {
name,
layout,
layout_dir,
cwd,
} => {
let current_dir = get_current_dir();
let cwd = cwd
.map(|cwd| current_dir.join(cwd))
.or_else(|| Some(current_dir));
if let Some(layout_path) = layout {
let layout_dir =
layout_dir.or_else(|| get_layout_dir(find_default_config_dir()));
let (path_to_raw_layout, raw_layout, swap_layouts) =
Layout::stringified_from_path_or_default(Some(&layout_path), None)
Layout::stringified_from_path_or_default(Some(&layout_path), layout_dir)
.map_err(|e| format!("Failed to load layout: {}", e))?;
let layout = Layout::from_str(&raw_layout, path_to_raw_layout, swap_layouts.as_ref().map(|(f, p)| (f.as_str(), p.as_str())), cwd).map_err(|e| {
let stringified_error = match e {
Expand Down
4 changes: 2 additions & 2 deletions zellij-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ impl Setup {
/// file options, superceeding the config file options:
/// 1. command line options (`zellij options`)
/// 2. layout options
/// (`layout.yaml` / `zellij --layout`)
/// 3. config options (`config.yaml`)
/// (`layout.kdl` / `zellij --layout`)
/// 3. config options (`config.kdl`)
pub fn from_cli_args(cli_args: &CliArgs) -> Result<(Config, Layout, Options), ConfigError> {
// note that this can potentially exit the process
Setup::handle_setup_commands(cli_args);
Expand Down