summaryrefslogtreecommitdiffstats
path: root/zellij-utils
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-27 16:34:31 +0100
committerGitHub <noreply@github.com>2023-02-27 16:34:31 +0100
commit149cafc6d66086c5f42c3f2f82c442d438e5b2c4 (patch)
tree89c11faf8a90d82b68d0b47b82398c543ddcfa4e /zellij-utils
parentd20720f443c9b934f4db13701fd6f30202a773de (diff)
fix(cli): edit cwd (#2201)
* fix(cli): properly set cwd for edit panes * fix(layouts): properly set cwd for edit panes * style(fmt): rustfmt
Diffstat (limited to 'zellij-utils')
-rw-r--r--zellij-utils/src/cli.rs2
-rw-r--r--zellij-utils/src/input/actions.rs11
-rw-r--r--zellij-utils/src/input/command.rs3
-rw-r--r--zellij-utils/src/input/layout.rs35
-rw-r--r--zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap5
-rw-r--r--zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap5
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs7
7 files changed, 52 insertions, 16 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 40d451d19..2733f1c74 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -353,7 +353,7 @@ pub enum CliAction {
layout: Option<PathBuf>,
/// Default folder to look for layouts
- #[clap(short, long, value_parser, requires("layout"))]
+ #[clap(long, value_parser, requires("layout"))]
layout_dir: Option<PathBuf>,
/// Name of the new tab
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 467f6a58a..a47e79f47 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -152,7 +152,13 @@ pub enum Action {
/// If no direction is specified, will try to use the biggest available space.
NewPane(Option<Direction>, Option<String>), // String is an optional pane name
/// Open the file in a new pane using the default editor
- EditFile(PathBuf, Option<usize>, Option<Direction>, bool), // usize is an optional line number, bool is floating true/false
+ EditFile(
+ PathBuf,
+ Option<usize>,
+ Option<PathBuf>,
+ Option<Direction>,
+ bool,
+ ), // usize is an optional line number, Option<PathBuf> is an optional cwd, bool is floating true/false
/// Open a new floating pane
NewFloatingPane(Option<RunCommandAction>, Option<String>), // String is an optional pane name
/// Open a new tiled (embedded, non-floating) pane
@@ -317,13 +323,14 @@ impl Action {
.map(|cwd| current_dir.join(cwd))
.or_else(|| Some(current_dir));
if file.is_relative() {
- if let Some(cwd) = cwd {
+ if let Some(cwd) = cwd.as_ref() {
file = cwd.join(file);
}
}
Ok(vec![Action::EditFile(
file,
line_number,
+ cwd,
direction,
floating,
)])
diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs
index 3b6f25025..3d2a87ab3 100644
--- a/zellij-utils/src/input/command.rs
+++ b/zellij-utils/src/input/command.rs
@@ -5,7 +5,8 @@ use std::path::PathBuf;
#[derive(Debug, Clone)]
pub enum TerminalAction {
- OpenFile(PathBuf, Option<usize>), // path to file and optional line_number
+ OpenFile(PathBuf, Option<usize>, Option<PathBuf>), // path to file (should be absolute), optional line_number and an
+ // optional cwd
RunCommand(RunCommand),
}
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index a0d61b241..d6f5a2f7d 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -73,7 +73,7 @@ pub enum Run {
Plugin(RunPlugin),
#[serde(rename = "command")]
Command(RunCommand),
- EditFile(PathBuf, Option<usize>), // TODO: merge this with TerminalAction::OpenFile
+ EditFile(PathBuf, Option<usize>, Option<PathBuf>), // TODO: merge this with TerminalAction::OpenFile
Cwd(PathBuf),
}
@@ -108,13 +108,26 @@ impl Run {
},
(
Some(Run::Command(base_run_command)),
- Some(Run::EditFile(file_to_edit, line_number)),
+ Some(Run::EditFile(file_to_edit, line_number, edit_cwd)),
) => match &base_run_command.cwd {
- Some(cwd) => Some(Run::EditFile(cwd.join(&file_to_edit), *line_number)),
- None => Some(Run::EditFile(file_to_edit.clone(), *line_number)),
+ Some(cwd) => Some(Run::EditFile(
+ cwd.join(&file_to_edit),
+ *line_number,
+ Some(cwd.join(edit_cwd.clone().unwrap_or_default())),
+ )),
+ None => Some(Run::EditFile(
+ file_to_edit.clone(),
+ *line_number,
+ edit_cwd.clone(),
+ )),
},
- (Some(Run::Cwd(cwd)), Some(Run::EditFile(file_to_edit, line_number))) => {
- Some(Run::EditFile(cwd.join(&file_to_edit), *line_number))
+ (Some(Run::Cwd(cwd)), Some(Run::EditFile(file_to_edit, line_number, edit_cwd))) => {
+ let cwd = edit_cwd.clone().unwrap_or(cwd.clone());
+ Some(Run::EditFile(
+ cwd.join(&file_to_edit),
+ *line_number,
+ Some(cwd),
+ ))
},
(Some(_base), Some(other)) => Some(other.clone()),
(Some(base), _) => Some(base.clone()),
@@ -132,7 +145,15 @@ impl Run {
run_command.cwd = Some(cwd.clone());
},
},
- Run::EditFile(path_to_file, _line_number) => {
+ Run::EditFile(path_to_file, _line_number, edit_cwd) => {
+ match edit_cwd.as_mut() {
+ Some(edit_cwd) => {
+ *edit_cwd = cwd.join(&edit_cwd);
+ },
+ None => {
+ let _ = edit_cwd.insert(cwd.clone());
+ },
+ };
*path_to_file = cwd.join(&path_to_file);
},
Run::Cwd(path) => {
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap
index 34d0fb321..68661a9c5 100644
--- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap
+++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/input/./unit/layout_test.rs
-assertion_line: 1558
+assertion_line: 1614
expression: "format!(\"{:#?}\", layout)"
---
Layout {
@@ -21,6 +21,9 @@ Layout {
EditFile(
"/tmp/foo/bar",
None,
+ Some(
+ "/tmp/foo",
+ ),
),
),
borderless: false,
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap
index 298be4e00..47469139b 100644
--- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap
+++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/input/./unit/layout_test.rs
-assertion_line: 1574
+assertion_line: 1630
expression: "format!(\"{:#?}\", layout)"
---
Layout {
@@ -21,6 +21,9 @@ Layout {
EditFile(
"/tmp/foo/bar",
None,
+ Some(
+ "/tmp/foo/",
+ ),
),
),
borderless: false,
diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs
index 5d89fab1b..cf6afaf70 100644
--- a/zellij-utils/src/kdl/kdl_layout_parser.rs
+++ b/zellij-utils/src/kdl/kdl_layout_parser.rs
@@ -374,8 +374,10 @@ impl<'a> KdlLayoutParser<'a> {
hold_on_close,
hold_on_start,
}))),
- (None, Some(edit), Some(cwd)) => Ok(Some(Run::EditFile(cwd.join(edit), None))),
- (None, Some(edit), None) => Ok(Some(Run::EditFile(edit, None))),
+ (None, Some(edit), Some(cwd)) => {
+ Ok(Some(Run::EditFile(cwd.join(edit), None, Some(cwd))))
+ },
+ (None, Some(edit), None) => Ok(Some(Run::EditFile(edit, None, None))),
(Some(_command), Some(_edit), _) => Err(ConfigError::new_layout_kdl_error(
"cannot have both a command and an edit instruction for the same pane".into(),
pane_node.span().offset(),
@@ -962,7 +964,6 @@ impl<'a> KdlLayoutParser<'a> {
.unwrap_or(false);
let split_size = self.parse_split_size(kdl_node)?;
let children_split_direction = self.parse_split_direction(kdl_node)?;
- let is_part_of_stack = false;
let (external_children_index, pane_parts) = match kdl_children_nodes!(kdl_node) {
Some(children) => {
self.parse_child_pane_nodes_for_pane(&children, children_are_stacked)?