From 7a304b614356ad1a3a72d7d9024021dbd65c550f Mon Sep 17 00:00:00 2001 From: pkm Date: Fri, 8 Jul 2016 15:11:32 -0700 Subject: [PATCH 1/2] adding support for iterm2 ipython5 by sending cpaste as separate cmds --- textsender.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/textsender.py b/textsender.py index f7c20d8..8b88249 100644 --- a/textsender.py +++ b/textsender.py @@ -28,8 +28,8 @@ def is_python(self): def wrap_paste_magic_for_python(self, cmd): if self.is_python(): cmd = cmd.rstrip("\n") - if len(re.findall("\n", cmd)) > 0: - cmd = "%cpaste -q\n" + cmd + "\n--" + # if len(re.findall("\n", cmd)) > 0: + # cmd = "%cpaste -q\n" + cmd + "\n--\n" return cmd def send_text(self, cmd): @@ -82,6 +82,7 @@ def _dispatch_terminal(self, cmd): 'tell application "Terminal" to do script ' + cmd + ' in front window']) subprocess.check_call(args) + @staticmethod def iterm_version(): args = ['osascript', '-e', 'tell application "iTerm" to get version'] @@ -103,6 +104,14 @@ def _dispatch_iterm(self, cmd): 'to tell current session to write text ' ]) elif self.iterm_version() >= (2, 9): + if len(re.findall("\n", cmd)) > 0: + chunk = "%cpaste -q\n" + subprocess.check_call([ + 'osascript', '-e', + 'tell application "iTerm" to tell the current window ' + + 'to tell current session to write text "' + + self.escape_dquote(chunk) + '" without newline' + ]) n = 1000 chunks = [cmd[i:i+n] for i in range(0, len(cmd), n)] for chunk in chunks: @@ -112,11 +121,20 @@ def _dispatch_iterm(self, cmd): 'to tell current session to write text "' + self.escape_dquote(chunk) + '" without newline' ]) + if len(re.findall("\n", cmd)) > 0: + chunk = "\n--" + subprocess.check_call([ + 'osascript', '-e', + 'tell application "iTerm" to tell the current window ' + + 'to tell current session to write text "' + + self.escape_dquote(chunk) + '" without newline' + ]) subprocess.check_call([ 'osascript', '-e', 'tell application "iTerm" to tell the current window ' + 'to tell current session to write text ""' ]) + else: subprocess.check_call([ 'osascript', '-e', From 84d6950c5a4b4c42476676b38c57da732b6999c1 Mon Sep 17 00:00:00 2001 From: pkm Date: Fri, 8 Jul 2016 15:14:22 -0700 Subject: [PATCH 2/2] check that cmd is python --- textsender.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/textsender.py b/textsender.py index 8b88249..a0a2d0c 100644 --- a/textsender.py +++ b/textsender.py @@ -104,7 +104,7 @@ def _dispatch_iterm(self, cmd): 'to tell current session to write text ' ]) elif self.iterm_version() >= (2, 9): - if len(re.findall("\n", cmd)) > 0: + if self.is_python() and len(re.findall("\n", cmd)) > 0: chunk = "%cpaste -q\n" subprocess.check_call([ 'osascript', '-e', @@ -121,7 +121,7 @@ def _dispatch_iterm(self, cmd): 'to tell current session to write text "' + self.escape_dquote(chunk) + '" without newline' ]) - if len(re.findall("\n", cmd)) > 0: + if self.is_python() and len(re.findall("\n", cmd)) > 0: chunk = "\n--" subprocess.check_call([ 'osascript', '-e',