-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabz
executable file
·47 lines (35 loc) · 1.04 KB
/
abz
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
#!/usr/bin/env python3
import os
import click
pth = os.environ["ABOOK_FILE"]
from abook_parser.parser import AbookFile, Fzf
fzf = Fzf()
@click.command()
@click.option("-c", "--clipboard", is_flag=True, help="Copy to clipboard")
def main(clipboard: bool) -> None:
ab = AbookFile(path=pth)
mem: dict[str, dict[str, str]] = {}
feed = []
for contact in ab.contacts:
if "name" not in contact:
continue
key = contact["name"]
if "nick" in contact:
key += f" ({contact['nick']})"
mem[key] = contact
feed.append(key)
chosen = fzf.prompt(feed, "--no-multi")
if not chosen:
return
chosen = mem[chosen[0]]
picked = fzf.prompt([f"{key}={val}" for key, val in chosen.items()], "--multi")
if not picked:
return
print_items = [p.split("=", maxsplit=1)[1] for p in picked]
text = "\n".join(print_items)
click.echo(text)
if clipboard:
from pura.clipboard import clipcopy
clipcopy(text)
if __name__ == "__main__":
main()