|
13 | 13 | import re |
14 | 14 | import subprocess |
15 | 15 | import sys |
| 16 | +import tempfile |
16 | 17 |
|
17 | 18 |
|
18 | 19 | FilePosition = collections.namedtuple('FilePosition', ['filepath', 'linenumber']) |
@@ -146,21 +147,24 @@ def clear(arguments): |
146 | 147 |
|
147 | 148 | def _copy_stacktrace_to_clipboard(self, stacktrace): |
148 | 149 | stacktrace_text = '\n'.join('File "{}", line {:d},'.format(file, line) for file, line in reversed(stacktrace)) |
149 | | - platform_system = platform.system() |
150 | 150 | process = None |
151 | | - if platform_system == 'Darwin': |
152 | | - process = subprocess.Popen('pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE) |
| 151 | + if 'TMUX' in os.environ: |
| 152 | + process = subprocess.Popen(['tmux', 'load-buffer', '-'], stdin=subprocess.PIPE) |
153 | 153 | else: |
154 | | - # assume we are running on Linux |
155 | | - for cmd in (['xclip', '-selection', 'clipboard'], ['xsel', '--clipboard']): |
156 | | - try: |
157 | | - process = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
158 | | - break |
159 | | - except OSError: |
160 | | - pass |
| 154 | + platform_system = platform.system() |
| 155 | + if platform_system == 'Darwin': |
| 156 | + process = subprocess.Popen('pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE) |
161 | 157 | else: |
162 | | - print(prefix_output('Stacktrace cannot be copied to clipboard! Either install xclip or xsel.', |
163 | | - 'warning: ')) |
| 158 | + # assume we are running on Linux |
| 159 | + for cmd in (['xclip', '-selection', 'clipboard'], ['xsel', '--clipboard']): |
| 160 | + try: |
| 161 | + process = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
| 162 | + break |
| 163 | + except OSError: |
| 164 | + pass |
| 165 | + else: |
| 166 | + print(prefix_output('Stacktrace cannot be copied to clipboard! Either install xclip or xsel.', |
| 167 | + 'warning: ')) |
164 | 168 | if process is not None: |
165 | 169 | process.communicate(stacktrace_text.encode('utf-8')) |
166 | 170 |
|
|
0 commit comments