Skip to content

Commit 60f9e08

Browse files
author
hongyu9
committed
2 parents f159397 + 2d9e374 commit 60f9e08

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

jetbrains_plugin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Plugin basic information
22
pluginGroup=com.sina.weibo.agent
3-
pluginVersion=0.2.2
3+
pluginVersion=0.2.3
44

55
# Platform basic information
66
platformVersion=2023.3

jetbrains_plugin/src/main/kotlin/com/sina/weibo/agent/terminal/WeCoderTerminalCustomizer.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,40 @@ class WeCoderTerminalCustomizer : LocalTerminalCustomizer() {
161161
}
162162

163163
/**
164-
* Inject VSCode integration script for Zsh
164+
* Inject VSCode integration script for Zsh (safe with JetBrains shell integration)
165165
*/
166-
private fun injectZshScript(command: Array<String>, envs: MutableMap<String, String>, scriptPath: String): Array<String> {
167-
// Save user's original ZDOTDIR environment variable
168-
val userZdotdir = envs["ZDOTDIR"]
169-
?: System.getenv("ZDOTDIR")
170-
?: System.getProperty("user.home")
171-
172-
// 🔧 Protect the JETBRAINS_INTELLIJ_ZSH_DIR environment variable to prevent it from being cleared.
166+
private fun injectZshScript(
167+
command: Array<String>,
168+
envs: MutableMap<String, String>,
169+
scriptPath: String
170+
): Array<String> {
171+
// 1) If JetBrains' built-in zsh shell integration is already in place, avoid modifying ZDOTDIR to prevent conflicts.
173172
val jetbrainsZshDir = envs["JETBRAINS_INTELLIJ_ZSH_DIR"] ?: System.getenv("JETBRAINS_INTELLIJ_ZSH_DIR")
174-
if (jetbrainsZshDir != null) {
175-
envs["JETBRAINS_INTELLIJ_ZSH_DIR"] = jetbrainsZshDir
176-
logger.info("🔧 Preserved JETBRAINS_INTELLIJ_ZSH_DIR: $jetbrainsZshDir")
173+
val shellExeName = File(command[0]).name
174+
val looksLikeJbZsh = command[0].contains("/plugins/terminal/shell-integrations/zsh")
175+
176+
if (jetbrainsZshDir != null || looksLikeJbZsh) {
177+
logger.info("🔒 Detected JetBrains Zsh integration (JETBRAINS_INTELLIJ_ZSH_DIR=$jetbrainsZshDir, looksLikeJbZsh=$looksLikeJbZsh). Skip overriding ZDOTDIR.")
178+
// Still retain the user's original ZDOTDIR in the environment for on-demand use within scripts.
179+
val userZdotdir = envs["ZDOTDIR"] ?: System.getenv("ZDOTDIR") ?: System.getProperty("user.home")
180+
envs["USER_ZDOTDIR"] = userZdotdir
181+
return command
177182
}
178183

184+
// 2) Inject only when `scriptPath` appears to be a valid `ZDOTDIR` (at least containing `.zshrc`).
185+
val dir = File(scriptPath)
186+
val hasZshrc = File(dir, ".zshrc").exists()
187+
if (!dir.isDirectory || !hasZshrc) {
188+
logger.warn("🚫 Zsh script dir '$scriptPath' is invalid (dir=$dir, hasZshrc=$hasZshrc). Skip overriding ZDOTDIR.")
189+
return command
190+
}
191+
192+
// 3) Record and securely overwrite.
193+
val userZdotdir = envs["ZDOTDIR"] ?: System.getenv("ZDOTDIR") ?: System.getProperty("user.home")
179194
envs["USER_ZDOTDIR"] = userZdotdir
180195
envs["ZDOTDIR"] = scriptPath
181-
182-
logger.info("🔧 Saved original ZDOTDIR: $userZdotdir, set new ZDOTDIR: $scriptPath")
196+
197+
logger.info("🔧 Set ZDOTDIR to '$scriptPath' (saved original as USER_ZDOTDIR='$userZdotdir'), shell=$shellExeName")
183198
return command
184199
}
185200

jetbrains_plugin/src/main/kotlin/com/sina/weibo/agent/util/ProxyConfigUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object ProxyConfigUtil {
6161
val proxyConfig = HttpConfigurable.getInstance()
6262

6363
// Check PAC proxy
64-
if (proxyConfig.USE_PAC_URL) {
64+
if (proxyConfig.USE_PROXY_PAC) {
6565
val pacUrl = proxyConfig.PAC_URL
6666
if (!pacUrl.isNullOrEmpty()) {
6767
return ProxyConfig(null, null, pacUrl, "ide-pac")

0 commit comments

Comments
 (0)