summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-11-03 11:06:37 +0100
committerGitHub <noreply@github.com>2022-11-03 11:06:37 +0100
commit9ebc9b74eeed25b52ba0543ecceab25c7805642b (patch)
tree1f35b3409ee8808c3eb339d2ee6d7819b5d1f866
parent4905ae65b8084d9f6adc31f9260b5a3cca6c920b (diff)
fix(edit): treat cwd properly (#1904)
-rw-r--r--src/main.rs9
-rw-r--r--zellij-server/src/unit/screen_tests.rs3
-rw-r--r--zellij-utils/src/cli.rs8
-rw-r--r--zellij-utils/src/input/actions.rs4
4 files changed, 23 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 6203f0f16..94a6eb4b2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -46,13 +46,22 @@ fn main() {
direction,
line_number,
floating,
+ cwd,
})) = opts.command
{
+ let mut file = file;
+ let cwd = cwd.or_else(|| std::env::current_dir().ok());
+ if file.is_relative() {
+ if let Some(cwd) = cwd.as_ref() {
+ file = cwd.join(file);
+ }
+ }
let command_cli_action = CliAction::Edit {
file,
direction,
line_number,
floating,
+ cwd,
};
commands::send_action_to_session(command_cli_action, opts.session);
std::process::exit(0);
diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs
index f55b0a1c9..f0c625dc5 100644
--- a/zellij-server/src/unit/screen_tests.rs
+++ b/zellij-server/src/unit/screen_tests.rs
@@ -1943,6 +1943,7 @@ pub fn send_cli_edit_action_with_default_parameters() {
direction: None,
line_number: None,
floating: false,
+ cwd: None,
};
send_cli_action_to_server(
&session_metadata,
@@ -1980,6 +1981,7 @@ pub fn send_cli_edit_action_with_line_number() {
direction: None,
line_number: Some(100),
floating: false,
+ cwd: None,
};
send_cli_action_to_server(
&session_metadata,
@@ -2017,6 +2019,7 @@ pub fn send_cli_edit_action_with_split_direction() {
direction: Some(Direction::Down),
line_number: None,
floating: false,
+ cwd: None,
};
send_cli_action_to_server(
&session_metadata,
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index baa53b9a7..694032dc1 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -162,6 +162,10 @@ pub enum Sessions {
/// Open the new pane in floating mode
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
+
+ /// Change the working directory of the editor
+ #[clap(long, value_parser)]
+ cwd: Option<PathBuf>,
},
ConvertConfig {
old_config_file: PathBuf,
@@ -282,6 +286,10 @@ pub enum CliAction {
/// Open the new pane in floating mode
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
floating: bool,
+
+ /// Change the working directory of the editor
+ #[clap(long, value_parser)]
+ cwd: Option<PathBuf>,
},
/// Switch input mode of all connected clients [locked|pane|tab|resize|move|search|session]
SwitchMode { input_mode: InputMode },
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 189f3cd96..e0337da09 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -301,10 +301,12 @@ impl Action {
file,
line_number,
floating,
+ cwd,
} => {
let mut file = file;
+ let cwd = cwd.or_else(|| std::env::current_dir().ok());
if file.is_relative() {
- if let Some(cwd) = std::env::current_dir().ok() {
+ if let Some(cwd) = cwd {
file = cwd.join(file);
}
}