From 5e587333b51e9a00b634f10a9800bfbd4a7f11fc Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 24 Apr 2024 15:39:54 +0200 Subject: [PATCH] fix(plugins): respect default shell when configured in the $SHELL env variable (#3296) * fix(plugins): respect $SHELL alias for default shell * style(fmt): rustfmt * fix tests --- ...open_terminal_floating_plugin_command.snap | 4 +-- ...n_tests__open_terminal_plugin_command.snap | 4 +-- zellij-server/src/plugins/zellij_exports.rs | 33 ++++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_floating_plugin_command.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_floating_plugin_command.snap index 4c752eff..09752304 100644 --- a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_floating_plugin_command.snap +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_floating_plugin_command.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/plugins/./unit/plugin_tests.rs -assertion_line: 4246 +assertion_line: 4390 expression: "format!(\"{:#?}\", new_tab_event)" --- Some( @@ -8,7 +8,7 @@ Some( Some( RunCommand( RunCommand { - command: "", + command: ".", args: [], cwd: Some( "/path/to/my/file.rs", diff --git a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_plugin_command.snap b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_plugin_command.snap index 7c0fb608..425190e1 100644 --- a/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_plugin_command.snap +++ b/zellij-server/src/plugins/unit/snapshots/zellij_server__plugins__plugin_tests__open_terminal_plugin_command.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/plugins/./unit/plugin_tests.rs -assertion_line: 4169 +assertion_line: 4312 expression: "format!(\"{:#?}\", new_tab_event)" --- Some( @@ -8,7 +8,7 @@ Some( Some( RunCommand( RunCommand { - command: "", + command: ".", args: [], cwd: Some( "/path/to/my/file.rs", diff --git a/zellij-server/src/plugins/zellij_exports.rs b/zellij-server/src/plugins/zellij_exports.rs index 935e6ba0..b3dcbc23 100644 --- a/zellij-server/src/plugins/zellij_exports.rs +++ b/zellij-server/src/plugins/zellij_exports.rs @@ -515,11 +515,12 @@ fn open_file_in_place(env: &ForeignFunctionEnv, file_to_open: FileToOpen) { fn open_terminal(env: &ForeignFunctionEnv, cwd: PathBuf) { let error_msg = || format!("failed to open file in plugin {}", env.plugin_env.name()); let cwd = env.plugin_env.plugin_cwd.join(cwd); - let mut default_shell = env - .plugin_env - .default_shell - .clone() - .unwrap_or_else(|| TerminalAction::RunCommand(RunCommand::default())); + let mut default_shell = env.plugin_env.default_shell.clone().unwrap_or_else(|| { + TerminalAction::RunCommand(RunCommand { + command: env.plugin_env.path_to_default_shell.clone(), + ..Default::default() + }) + }); default_shell.change_cwd(cwd); let run_command_action: Option = match default_shell { TerminalAction::RunCommand(run_command) => Some(run_command.into()), @@ -536,11 +537,12 @@ fn open_terminal_floating( ) { let error_msg = || format!("failed to open file in plugin {}", env.plugin_env.name()); let cwd = env.plugin_env.plugin_cwd.join(cwd); - let mut default_shell = env - .plugin_env - .default_shell - .clone() - .unwrap_or_else(|| TerminalAction::RunCommand(RunCommand::default())); + let mut default_shell = env.plugin_env.default_shell.clone().unwrap_or_else(|| { + TerminalAction::RunCommand(RunCommand { + command: env.plugin_env.path_to_default_shell.clone(), + ..Default::default() + }) + }); default_shell.change_cwd(cwd); let run_command_action: Option = match default_shell { TerminalAction::RunCommand(run_command) => Some(run_command.into()), @@ -553,11 +555,12 @@ fn open_terminal_floating( fn open_terminal_in_place(env: &ForeignFunctionEnv, cwd: PathBuf) { let error_msg = || format!("failed to open file in plugin {}", env.plugin_env.name()); let cwd = env.plugin_env.plugin_cwd.join(cwd); - let mut default_shell = env - .plugin_env - .default_shell - .clone() - .unwrap_or_else(|| TerminalAction::RunCommand(RunCommand::default())); + let mut default_shell = env.plugin_env.default_shell.clone().unwrap_or_else(|| { + TerminalAction::RunCommand(RunCommand { + command: env.plugin_env.path_to_default_shell.clone(), + ..Default::default() + }) + }); default_shell.change_cwd(cwd); let run_command_action: Option = match default_shell { TerminalAction::RunCommand(run_command) => Some(run_command.into()),