Terminal shell integration with zsh
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 10 Oct 2016 21:08:47 +0000 (23:08 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 11 Oct 2016 02:14:51 +0000 (04:14 +0200)
plugins/terminal/resources/.zshrc [new file with mode: 0644]
plugins/terminal/src/org/jetbrains/plugins/terminal/LocalTerminalDirectRunner.java

diff --git a/plugins/terminal/resources/.zshrc b/plugins/terminal/resources/.zshrc
new file mode 100644 (file)
index 0000000..f41635e
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
+bindkey '^[^[[C' forward-word
+bindkey '^[^[[D' backward-word
+
+if [ -f "$HOME/.zshrc" ]; then
+     source "$HOME/.zshrc"
+  fi
+
+if [ -n "$JEDITERM_SOURCE" ]
+then
+  source $JEDITERM_SOURCE
+fi
\ No newline at end of file
index a106ae05c316755a18301081d495f66b7355976d..2a07d9e99870a3b64371fc6a2829af8ab8450c42 100644 (file)
@@ -76,7 +76,11 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
       }
       try {
 
-        URL resource = LocalTerminalDirectRunner.class.getClassLoader().getResource("jediterm-" + shellName + ".in");
+        String rcfile = "jediterm-" + shellName + ".in";
+        if ("zsh".equals(shellName)) {
+          rcfile = ".zshrc";
+        }
+        URL resource = LocalTerminalDirectRunner.class.getClassLoader().getResource(rcfile);
         if (resource != null) {
           URI uri = resource.toURI();
           return uri.getPath();
@@ -186,17 +190,12 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
 
 
         if (rcFilePath != null &&
-            shellIntegration &&
-            (shellName.equals("bash") || shellName.equals("sh"))) {
-          result.add("--rcfile");
-          result.add(rcFilePath);
-          int idx = command.indexOf("--rcfile");
-          if (idx >= 0) {
-            command.remove(idx);
-            if (idx < command.size()) {
-              envs.put("JEDITERM_SOURCE", command.get(idx));
-              command.remove(idx);
-            }
+            shellIntegration) {
+          if (shellName.equals("bash") || shellName.equals("sh")) {
+            addRcFileArgument(envs, command, result, rcFilePath, "--rcfile");
+          }
+          else if (shellName.equals("zsh")) {
+            envs.put("ZDOTDIR", new File(rcFilePath).getParent());
           }
         }
 
@@ -219,6 +218,22 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
     }
   }
 
+  private static void addRcFileArgument(Map<String, String> envs,
+                                        List<String> command,
+                                        List<String> result,
+                                        String rcFilePath, String rcfileOption) {
+    result.add(rcfileOption);
+    result.add(rcFilePath);
+    int idx = command.indexOf(rcfileOption);
+    if (idx >= 0) {
+      command.remove(idx);
+      if (idx < command.size()) {
+        envs.put("JEDITERM_SOURCE", command.get(idx));
+        command.remove(idx);
+      }
+    }
+  }
+
   private static boolean loginOrInteractive(List<String> command) {
     return command.contains("-i") || command.contains("--login") || command.contains("-l");
   }