Last active
August 29, 2015 14:06
-
-
Save bfredl/888e2b7c2b378d6953ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
class NvimClipboard(object): | |
def __init__(self, vim): | |
self.provides = ['clipboard'] | |
def sel_name(self, reg): | |
return 'clipboard' if reg == '+' else 'primary' | |
def clipboard_get(self, reg): | |
txt = Popen(['xclip', '-selection', self.sel_name(reg), '-o'], stdout=PIPE).communicate()[0] | |
# emulate vim behavior | |
if txt.endswith('\n'): | |
txt = txt[:-1] | |
regtype = 'V' | |
else: | |
regtype = 'v' | |
return txt.split('\n'), regtype | |
def clipboard_set(self, lines, regtype, reg): | |
txt = '\n'.join([line for line in lines]) | |
if regtype == 'V': | |
txt = txt + '\n' | |
_cmd = ['xclip', '-selection', self.sel_name(reg)] | |
Popen(_cmd, stdin=PIPE).communicate(txt) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops, lost the import when copying, it should work now.