-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect-unicode-char
executable file
·54 lines (45 loc) · 1.12 KB
/
select-unicode-char
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
#!/usr/bin/env python3
# Author: Jan Larres <[email protected]>
# License: MIT/X11
import os
import sys
import unicodedata
from subprocess import CalledProcessError, run
UNICODE_END = 0xE01EF
def main() -> int:
chars = [
c + "\t" + name
for c, name in (
(c, unicodedata.name(c, None)) for c in map(chr, range(UNICODE_END))
)
if name is not None
]
stdin = "\n".join(chars)
try:
if os.environ.get("XDG_SESSION_TYPE") == "wayland":
cmd = ["fuzzel", "--dmenu"]
else:
cmd = ["rofi", "-dmenu", "-i"]
p = run(
cmd,
input=stdin,
text=True,
check=True,
capture_output=True,
)
except CalledProcessError:
return 1
selected = p.stdout.splitlines()[0].split("\t")[0]
try:
p = run(
["cb"],
input=selected,
text=True,
check=True,
)
except Exception as e:
run(["zenity", "--error", f"--text={e}"], check=True)
raise
return 0
if __name__ == "__main__":
sys.exit(main())