diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-02-26 22:11:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-26 22:11:08 +0100 |
commit | 52de5b7db048d944ca6df93192be9b0e54fd7269 (patch) | |
tree | d039e13654fcae533dbeed8754315de918a49303 /zellij-utils | |
parent | a1f563517681d91bc44e549c038a2af6a60ea718 (diff) |
fix(cli): new-tab now also looks in layout_dir for layouts (#2198)
* fix(cli): the new-tab action now also searches for layouts in the layout dir
* style(fmt): rustfmt
* fix(tests): add missing parameter to cli action
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/src/cli.rs | 4 | ||||
-rw-r--r-- | zellij-utils/src/input/actions.rs | 12 | ||||
-rw-r--r-- | zellij-utils/src/setup.rs | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index ea0b8d728..40d451d19 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -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>, diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index a4f4b74f6..467f6a58a 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -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}; @@ -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 { diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 2c4d89899..0086c6a99 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -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); |