diff --git a/textsender.py b/textsender.py index f7c20d8..a0a2d0c 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 self.is_python() and 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 self.is_python() and 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',