From eafaa138b1c1a65c33ccc2b501852121618f42c5 Mon Sep 17 00:00:00 2001 From: ifengqi <362254883@qq.com> Date: Fri, 13 Sep 2024 18:17:45 +0800 Subject: [PATCH] Fix loading the shell environment in Windows. (#3499) --- lapce-app/src/app.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lapce-app/src/app.rs b/lapce-app/src/app.rs index 1b028b54..22037ddc 100644 --- a/lapce-app/src/app.rs +++ b/lapce-app/src/app.rs @@ -3942,7 +3942,7 @@ pub fn launch() { } /// Uses a login shell to load the correct shell environment for the current user. -fn load_shell_env() { +pub fn load_shell_env() { use std::process::Command; use tracing::warn; @@ -3969,7 +3969,10 @@ fn load_shell_env() { command.args(["--login", "-c", "printenv"]); #[cfg(windows)] - command.args(["{ ls env: | foreach { '{0}={1}' -f $_.Name, $_.Value } }"]); + command.args(&[ + "-Command", + "Get-ChildItem env: | ForEach-Object { \"{0}={1}\" -f $_.Name, $_.Value }", + ]); let env = match command.output() { Ok(output) => String::from_utf8(output.stdout).unwrap_or_default(), @@ -3985,7 +3988,8 @@ fn load_shell_env() { env.split('\n') .filter_map(|line| line.split_once('=')) - .for_each(|(key, value)| { + .for_each(|(key, value)| unsafe { + let value = value.trim_matches('\r'); if let Ok(v) = std::env::var(key) { if v != value { warn!("Overwriting '{key}', previous value: '{v}', new value '{value}'");