diff options
| author | Jason Ledbetter <jasonbrent@gmail.com> | 2011-06-22 21:56:20 -0400 |
|---|---|---|
| committer | Jason Ledbetter <jasonbrent@gmail.com> | 2011-06-22 21:56:20 -0400 |
| commit | cbcb1b53527a838c9db3f559f517c7d13284a943 (patch) | |
| tree | 589f31e166c365ea41b4921af8b1ce1a31985dec /cmd2.py | |
| parent | 8af15d852a0096f2691da9432ba0952c131e7556 (diff) | |
| download | cmd2-git-cbcb1b53527a838c9db3f559f517c7d13284a943.tar.gz | |
Additional support for native pbcopy for clipboard redirect (">") on MacOSX.
Diffstat (limited to 'cmd2.py')
| -rwxr-xr-x | cmd2.py | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -152,6 +152,9 @@ class PasteBufferError(EnvironmentError): errmsg = """Redirecting to or from paste buffer requires pywin32 to be installed on operating system. Download from http://sourceforge.net/projects/pywin32/""" + elif sys.platform[:3] == 'dar': + # Use built in pbcopy on Mac OSX + pass else: errmsg = """Redirecting to or from paste buffer requires xclip to be installed on operating system. @@ -183,6 +186,25 @@ if subprocess.mswindows: def get_paste_buffer(*args): raise OSError, pastebufferr % ('pywin32', 'Download from http://sourceforge.net/projects/pywin32/') write_to_paste_buffer = get_paste_buffer +elif sys.platform == 'darwin': + can_clip = False + try: + # test for pbcopy - AFAIK, should always be installed on MacOS + subprocess.check_call('pbcopy -help', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + can_clip = True + except (subprocess.CalledProcessError, OSError, IOError): + pass + if can_clip: + def get_paste_buffer(): + pbcopyproc = subprocess.Popen('pbcopy -help', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + return pbcopyproc.stdout.read() + def write_to_paste_buffer(txt): + pbcopyproc = subprocess.Popen('pbcopy', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + pbcopyproc.communicate(txt.encode()) + else: + def get_paste_buffer(*args): + raise OSError, pastebufferr % ('pbcopy', 'On MacOS X - error should not occur - part of the default installation') + write_to_paste_buffer = get_paste_buffer else: can_clip = False try: |
