summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ledbetter <jasonbrent@gmail.com>2011-06-22 21:56:20 -0400
committerJason Ledbetter <jasonbrent@gmail.com>2011-06-22 21:56:20 -0400
commit6194bbe2f826137116b5d715a99c7531929b9a70 (patch)
tree589f31e166c365ea41b4921af8b1ce1a31985dec
parent3db47c201dd6b24258a8808842468c120a4629d8 (diff)
downloadcmd2-hg-6194bbe2f826137116b5d715a99c7531929b9a70.tar.gz
Additional support for native pbcopy for clipboard redirect (">") on MacOSX.
-rwxr-xr-xcmd2.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd2.py b/cmd2.py
index bf98652..bedae38 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -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: