Add config item clipboard_cmd, with a default of 'pbcopy w' on Darwin and 'xclip' on everything else. This will allow the user to use any command for the clipboard, including 'wl-copy' for Wayland (addressing issue #693 on Github). With his change, significant simplifications could be made to clipboard.py - the copy_*() functions have been removed and combined into copy(). With this simplification, the old OSX test is obsolete, and new OSX tests are needed (need a way to simulate sys.platform).
26 lines
660 B
Python
26 lines
660 B
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
import sys
|
|
import subprocess
|
|
|
|
def _subprocess_copy(text, args_list):
|
|
p = subprocess.Popen(args_list, stdin=subprocess.PIPE, close_fds=True)
|
|
p.communicate(input=text.encode('utf-8'))
|
|
|
|
|
|
def copy(text, cmd):
|
|
"""
|
|
Copy text to OS clipboard.
|
|
"""
|
|
|
|
# If no command is specified (i.e. the config option is empty) try
|
|
# to find a reasonable default based on the operating system
|
|
if cmd is None:
|
|
if sys.platform == 'darwin':
|
|
cmd = 'pbcopy w'
|
|
else: # For Linux, BSD, cygwin, etc.
|
|
cmd = 'xclip'
|
|
|
|
_subprocess_copy(text, cmd.split())
|