In case of sh shell source command with -c option as pure sh doesn't have --rcfile...
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 10 Oct 2016 19:02:45 +0000 (21:02 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 10 Oct 2016 19:02:45 +0000 (21:02 +0200)
platform/util/src/com/intellij/util/EnvironmentUtil.java
python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt

index dc31d03bd7c49e659355f21debe8c33e4b314c5c..4588fc1dd8a45fa16a25dd796d18e991244318e6 100644 (file)
@@ -173,8 +173,15 @@ public class EnvironmentUtil {
       File envFile = FileUtil.createTempFile("intellij-shell-env.", ".tmp", false);
       try {
         List<String> command = getShellProcessCommand();
-        command.add("-c");
-        command.add("'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'");
+
+        int idx = command.indexOf("-c");
+        if (idx>=0) {
+          // if there is already a command append command to the end
+          command.set(idx + 1, command.get(idx+1) + ";" + "'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'");
+        } else {
+          command.add("-c");
+          command.add("'" + reader.getAbsolutePath() + "' '" + envFile.getAbsolutePath() + "'");
+        }
 
         LOG.info("loading shell env: " + StringUtil.join(command, " "));
 
index c221510fa35740809ca3632a014ebc204a61b9a5..c91d77c3a34aa6d368a0af377c2fc55b693f2c42 100644 (file)
@@ -80,7 +80,12 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE
       throw Exception("shell:" + shellPath)
     }
 
-    return if (activate != null) mutableListOf(shellPath, "--rcfile", activate, "-i")
+    return if (activate != null)
+      if (File(shellPath).name == "sh") {
+        mutableListOf(shellPath, "-i", "-c", "source '$activate'")
+      } else {
+        mutableListOf(shellPath, "--rcfile", activate, "-i")
+      }
     else super.getShellProcessCommand()
   }