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 | 6194bbe2f826137116b5d715a99c7531929b9a70 (patch) | |
tree | 589f31e166c365ea41b4921af8b1ce1a31985dec | |
parent | 3db47c201dd6b24258a8808842468c120a4629d8 (diff) | |
download | cmd2-hg-6194bbe2f826137116b5d715a99c7531929b9a70.tar.gz |
Additional support for native pbcopy for clipboard redirect (">") on MacOSX.
-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: |