-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfzf.py
33 lines (28 loc) · 812 Bytes
/
fzf.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
import subprocess
from .model import PickleMappingEntry, VonIndex, setCache
from .puid import inferPUID
def _fzf_line(entry: PickleMappingEntry) -> str:
puid = inferPUID(entry.source)
return f"{puid}\t{entry.source:<13}\t{entry.desc}"
def fzf_choose() -> str:
with VonIndex() as index:
choices = "\n".join(_fzf_line(entry) for entry in index.values())
chosen = subprocess.check_output(
args=[
"fzf",
"-e",
"--tabstop",
"12",
"-d",
r"\t",
"--preview",
"python -m von show {2}",
"--preview-window",
"down",
],
input=choices,
text=True,
)
source = chosen.split("\t")[1].strip()
setCache([index[source]])
return source