Merge remote-tracking branch 'origin/master'
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 9 Nov 2016 18:50:55 +0000 (19:50 +0100)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 9 Nov 2016 18:50:55 +0000 (19:50 +0100)
plugins/terminal/resources/.zshrc
plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java
python/python-terminal/src/com/jetbrains/python/sdk/PyVirtualEnvTerminalCustomizer.kt

index f41635e190e92d8b4178998b21a78973047b85b8..72c38b82dc24d4b4b8886a6bf9cd1dd1e7ccdcf5 100644 (file)
@@ -4,9 +4,14 @@
 bindkey '^[^[[C' forward-word
 bindkey '^[^[[D' backward-word
 
+if [ -n "$JEDITERM_USER_RCFILE" ]
+then
+  source $JEDITERM_USER_RCFILE
+fi
+
 if [ -f "$HOME/.zshrc" ]; then
      source "$HOME/.zshrc"
-  fi
+fi
 
 if [ -n "$JEDITERM_SOURCE" ]
 then
index e2a5119c5dedaa75dcd3b586c604f0a3ae8267e4..bdeffe83f598cfb424c6714c5164bf45bc3b47e3 100644 (file)
@@ -26,8 +26,10 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.CharsetToolkit;
 import com.intellij.util.ArrayUtil;
+import com.intellij.util.EnvironmentUtil;
 import com.intellij.util.concurrency.AppExecutorUtil;
 import com.intellij.util.containers.HashMap;
 import com.jediterm.pty.PtyProcessTtyConnector;
@@ -53,6 +55,8 @@ import java.util.concurrent.Future;
  */
 public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess> {
   private static final Logger LOG = Logger.getInstance(LocalTerminalDirectRunner.class);
+  public static final String JEDITERM_USER_RCFILE = "JEDITERM_USER_RCFILE";
+  public static final String ZDOTDIR = "ZDOTDIR";
 
   private final Charset myDefaultCharset;
 
@@ -128,7 +132,9 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
     }
 
     try {
-      return PtyProcess.exec(command, envs, directory != null ? directory : TerminalProjectOptionsProvider.Companion.getInstance(myProject).getStartingDirectory());
+      return PtyProcess.exec(command, envs, directory != null
+                                            ? directory
+                                            : TerminalProjectOptionsProvider.Companion.getInstance(myProject).getStartingDirectory());
     }
     catch (IOException e) {
       throw new ExecutionException(e);
@@ -189,7 +195,13 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
             addRcFileArgument(envs, command, result, rcFilePath, "--rcfile");
           }
           else if (shellName.equals("zsh")) {
-            envs.put("ZDOTDIR", new File(rcFilePath).getParent());
+            if (StringUtil.isNotEmpty(EnvironmentUtil.getEnvironmentMap().get(ZDOTDIR))) {
+              File zshRc = new File(FileUtil.expandUserHome(envs.get(ZDOTDIR)), ".zshrc");
+              if (zshRc.exists()) {
+                envs.put(JEDITERM_USER_RCFILE, zshRc.getAbsolutePath());
+              }
+            }
+            envs.put(ZDOTDIR, new File(rcFilePath).getParent());
           }
         }
 
@@ -222,7 +234,7 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
     if (idx >= 0) {
       command.remove(idx);
       if (idx < command.size()) {
-        envs.put("JEDITERM_USER_RCFILE", FileUtil.expandUserHome(command.get(idx)));
+        envs.put(JEDITERM_USER_RCFILE, FileUtil.expandUserHome(command.get(idx)));
         command.remove(idx);
       }
     }
index 1a359be3d0ee743adefdb0f45a4f736762c8f87c..898db01029ea5034a842eb7c514cb3ac2464b9a0 100644 (file)
@@ -45,14 +45,16 @@ class PyVirtualEnvTerminalCustomizer : LocalTerminalCustomizer() {
         val shellPath = command[0]
         val shellName = File(shellPath).name
 
-        if (shellName == "bash" || (SystemInfo.isMac && shellName == "sh")) {
+        if (shellName == "bash" || (SystemInfo.isMac && shellName == "sh") || (shellName == "zsh")) {
           //for bash we pass activate script to jediterm shell integration (see jediterm-bash.in) to source it there
           findActivateScript(path, shellPath)?.let { activate -> envs.put("JEDITERM_SOURCE", activate) }
         }
         else {
           //for other shells we read envs from activate script by the default shell and pass them to the process
           val reader = PyVirtualEnvReader(path)
-          reader.activate?.let { envs.putAll(reader.readShellEnv()) }
+          reader.activate?.let {
+            envs.putAll(reader.readShellEnv().filterKeys { k -> k in arrayOf("PATH", "PS1", "VIRTUAL_ENV", "PYTHONHOME") })
+          }
         }
 
       }