aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-26 22:11:08 +0100
committerGitHub <noreply@github.com>2023-02-26 22:11:08 +0100
commit52de5b7db048d944ca6df93192be9b0e54fd7269 (patch)
treed039e13654fcae533dbeed8754315de918a49303
parentdocs(changel0g): tab focus fix (diff)
downloadsl0ppij-52de5b7db048d944ca6df93192be9b0e54fd7269.tar.gz
sl0ppij-52de5b7db048d944ca6df93192be9b0e54fd7269.tar.xz
sl0ppij-52de5b7db048d944ca6df93192be9b0e54fd7269.zip
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
-rw-r--r--zellij-server/src/unit/screen_tests.rs2
-rw-r--r--zellij-utils/src/cli.rs4
-rw-r--r--zellij-utils/src/input/actions.rs12
-rw-r--r--zellij-utils/src/setup.rs4
4 files changed, 18 insertions, 4 deletions
diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs
index 616989d1..bf01fded 100644
--- a/zellij-server/src/unit/screen_tests.rs
+++ b/zellij-server/src/unit/screen_tests.rs
@@ -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(
@@ -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(
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index ea0b8d72..40d451d1 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 a4f4b74f..467f6a58 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 2c4d8989..0086c6a9 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);