-
Notifications
You must be signed in to change notification settings - Fork 1
/
rofi_clipboard.py
executable file
·58 lines (48 loc) · 1.25 KB
/
rofi_clipboard.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
#!/usr/bin/env python3
# https://github.com/albertlauncher/python/blob/master/CopyQ.py
import json
import subprocess as sp
copyq_script_getAll = r"""
var result=[];
for ( var i = 0; i < size(); ++i ) {
var obj = {};
obj.row = i;
obj.mimetypes = str(read("?", i)).split("\n");
obj.mimetypes.pop();
obj.text = str(read(i));
result.push(obj);
}
JSON.stringify(result);
"""
if __name__ == "__main__":
p = sp.run(
"copyq -".split(),
input=copyq_script_getAll,
encoding="utf-8",
stdout=sp.PIPE,
stderr=sp.PIPE,
)
json_arr = json.loads(p.stdout)
items = []
for json_obj in json_arr:
text = json_obj["text"]
text = " ".join(filter(None, text.replace("\n", " ").split(" ")))
items.append(text)
title = "rofi-copyq"
rofi = f"rofi -dmenu -i -p {title} -format i".split()
rofi_input = "\n".join(x for x in items)
p = sp.run(
rofi,
input=rofi_input,
encoding="utf-8",
stdout=sp.PIPE,
stderr=sp.PIPE,
)
if p.returncode == 0:
num = p.stdout.strip()
sp.run(
f"copyq select({num});".split(),
encoding="utf-8",
stdout=sp.PIPE,
stderr=sp.PIPE,
)