aboutsummaryrefslogtreecommitdiff
path: root/src/platform/unix_common.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/unix_common.rs')
-rw-r--r--src/platform/unix_common.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/platform/unix_common.rs b/src/platform/unix_common.rs
index b997049f..ce5bba00 100644
--- a/src/platform/unix_common.rs
+++ b/src/platform/unix_common.rs
@@ -228,11 +228,29 @@ fn datetime_from_tm(value: &libc::tm) -> Option<time::PrimitiveDateTime> {
Some(time::PrimitiveDateTime::new(date, time))
}
+pub(crate) fn set_default_plugin_pane_pwd(env: &mut Vec<(String, String)>, cwd: &std::path::Path) {
+ if !env.iter().any(|(key, _)| key == "PWD") {
+ env.push(("PWD".to_string(), cwd.display().to_string()));
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
#[test]
+ fn plugin_pane_pwd_defaults_to_cwd_without_overriding_explicit_env() {
+ let cwd = Path::new("/plugin-cwd");
+ let mut derived = vec![("OTHER".to_string(), "value".to_string())];
+ set_default_plugin_pane_pwd(&mut derived, cwd);
+ assert!(derived.contains(&("PWD".to_string(), "/plugin-cwd".to_string())));
+
+ let mut explicit = vec![("PWD".to_string(), "/caller-pwd".to_string())];
+ set_default_plugin_pane_pwd(&mut explicit, cwd);
+ assert_eq!(explicit, [("PWD".to_string(), "/caller-pwd".to_string())]);
+ }
+
+ #[test]
fn remote_ssh_config_dir_rejects_overlong_control_socket_name() {
let err = create_remote_ssh_config_dir(&"x".repeat(200)).unwrap_err();
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);