mirror of
https://github.com/zellij-org/zellij.git
synced 2026-10-11 22:50:07 +00:00
Allow plugins to read env vars present upon session creation (behind permission) (#4700)
* allow plugins to read environment variables * rustfmt * add pr
This commit is contained in:
+21
-1
@@ -19,7 +19,8 @@ use zellij_utils::plugin_api::plugin_command::{
|
||||
ProtobufEditLayoutResponse, ProtobufFocusOrCreateTabResponse,
|
||||
ProtobufGenerateRandomNameResponse, ProtobufGetFocusedPaneInfoResponse,
|
||||
ProtobufGetLayoutDirResponse, ProtobufGetPaneCwdResponse, ProtobufGetPaneInfoResponse,
|
||||
ProtobufGetPanePidResponse, ProtobufGetPaneRunningCommandResponse, ProtobufGetTabInfoResponse,
|
||||
ProtobufGetPanePidResponse, ProtobufGetPaneRunningCommandResponse,
|
||||
ProtobufGetSessionEnvironmentVariablesResponse, ProtobufGetTabInfoResponse,
|
||||
ProtobufNewTabResponse, ProtobufNewTabsResponse, ProtobufOpenCommandPaneBackgroundResponse,
|
||||
ProtobufOpenCommandPaneFloatingNearPluginResponse, ProtobufOpenCommandPaneFloatingResponse,
|
||||
ProtobufOpenCommandPaneInPlaceOfPluginResponse, ProtobufOpenCommandPaneInPlaceResponse,
|
||||
@@ -176,6 +177,25 @@ pub fn get_layout_dir() -> String {
|
||||
response.layout_dir
|
||||
}
|
||||
|
||||
pub fn get_session_environment_variables() -> BTreeMap<String, String> {
|
||||
let plugin_command = PluginCommand::GetSessionEnvironmentVariables;
|
||||
let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
|
||||
|
||||
object_to_stdout(&protobuf_plugin_command.encode_to_vec());
|
||||
unsafe { host_run_plugin_command() };
|
||||
|
||||
let response = ProtobufGetSessionEnvironmentVariablesResponse::decode(
|
||||
bytes_from_stdin().unwrap().as_slice(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
response
|
||||
.env_vars
|
||||
.into_iter()
|
||||
.map(|env_var| (env_var.name, env_var.value))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the focused pane ID and tab index for the client associated with this plugin.
|
||||
pub fn get_focused_pane_info() -> Result<(usize, PaneId), String> {
|
||||
let plugin_command = PluginCommand::GetFocusedPaneInfo;
|
||||
|
||||
Reference in New Issue
Block a user