fix(plugins): allow switching to a new session with cwd without specifying a layout (#3676)

This commit is contained in:
Aram Drevekenin 2024-10-14 16:44:28 +02:00 committed by GitHub
parent 99e9a345d3
commit 618e0f7a34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 4 deletions

View file

@ -483,6 +483,10 @@ pub(crate) fn start_client(opts: CliArgs) {
log::error!("Failed to parse new session layout: {:?}", e); log::error!("Failed to parse new session layout: {:?}", e);
}, },
} }
} else {
if let Some(cwd) = reconnect_to_session.cwd.as_ref() {
config_options.default_cwd = Some(cwd.clone());
}
} }
is_a_reconnect = true; is_a_reconnect = true;

View file

@ -426,9 +426,13 @@ pub(crate) fn plugin_thread_main(
let mut plugin_ids: HashMap<RunPluginOrAlias, Vec<PluginId>> = HashMap::new(); let mut plugin_ids: HashMap<RunPluginOrAlias, Vec<PluginId>> = HashMap::new();
tab_layout = tab_layout.or_else(|| Some(layout.new_tab().0)); tab_layout = tab_layout.or_else(|| Some(layout.new_tab().0));
tab_layout tab_layout.as_mut().map(|t| {
.as_mut() t.populate_plugin_aliases_in_layout(&plugin_aliases);
.map(|t| t.populate_plugin_aliases_in_layout(&plugin_aliases)); if let Some(cwd) = cwd.as_ref() {
t.add_cwd_to_layout(cwd);
}
t
});
floating_panes_layout.iter_mut().for_each(|f| { floating_panes_layout.iter_mut().for_each(|f| {
f.run f.run
.as_mut() .as_mut()

View file

@ -721,6 +721,18 @@ pub fn switch_session_with_layout(name: Option<&str>, layout: LayoutInfo, cwd: O
unsafe { host_run_plugin_command() }; unsafe { host_run_plugin_command() };
} }
/// Switch to a session with the given name, create one if no name is given
pub fn switch_session_with_cwd(name: Option<&str>, cwd: Option<PathBuf>) {
let plugin_command = PluginCommand::SwitchSession(ConnectToSession {
name: name.map(|n| n.to_string()),
cwd,
..Default::default()
});
let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
object_to_stdout(&protobuf_plugin_command.encode_to_vec());
unsafe { host_run_plugin_command() };
}
/// Switch to a session with the given name, focusing either the provided pane_id or the provided /// Switch to a session with the given name, focusing either the provided pane_id or the provided
/// tab position (in that order) /// tab position (in that order)
pub fn switch_session_with_focus( pub fn switch_session_with_focus(

View file

@ -960,7 +960,7 @@ impl PermissionType {
"Access Zellij state (Panes, Tabs and UI)".to_owned() "Access Zellij state (Panes, Tabs and UI)".to_owned()
}, },
PermissionType::ChangeApplicationState => { PermissionType::ChangeApplicationState => {
"Change Zellij state (Panes, Tabs and UI)".to_owned() "Change Zellij state (Panes, Tabs and UI) and run commands".to_owned()
}, },
PermissionType::OpenFiles => "Open files (eg. for editing)".to_owned(), PermissionType::OpenFiles => "Open files (eg. for editing)".to_owned(),
PermissionType::RunCommands => "Run commands".to_owned(), PermissionType::RunCommands => "Run commands".to_owned(),