-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyxFunc.py
63 lines (48 loc) · 1.27 KB
/
lyxFunc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import subprocess
def getClipboard():
'''IO(string)'''
xsel = ('xsel', '-o', '--clipboard')
ps = subprocess.Popen(xsel, stdin=subprocess.PIPE,stdout=subprocess.PIPE)
return ps.stdout.read()
def pasteToClipboard(content):
'''
string->IO()
'''
xsel = ('xsel', '-i', '--clipboard')
ps = subprocess.Popen(xsel, stdin=subprocess.PIPE)
ps.stdin.write(content.encode())
ps.stdin.close()
ps.wait()
FIFO_LYX_IN = '/home/chengzhengqian/.lyxpipe.in'
LYX_CMD_FORMAT = '"LYXCMD:lyxFunc:{0}:{1}"'
def runLyxFunction(action, args):
'''
string->string->IO()
'''
cmd = "echo " + LYX_CMD_FORMAT.format(action, args) + " > " + FIFO_LYX_IN
print("exec:", cmd)
subprocess.Popen(["bash", '-c', cmd])
def insetEnd():
'''
IO()
'''
runLyxFunction("inset-end", '')
def lineEnd():
'''
IO()
'''
runLyxFunction("line-end", '')
def charForward():
runLyxFunction("char-forward",'')
def charBackward():
runLyxFunction("char-backward",'')
def listingInsert():
runLyxFunction("listing-insert",'')
def copy():
runLyxFunction("copy",'')
def paste():
runLyxFunction("paste",'')
def insertString(content):
runLyxFunction("self-insert",content)
def message(msg):
runLyxFunction("message",msg)