-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpasscast.py
executable file
·56 lines (45 loc) · 1.59 KB
/
passcast.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
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title pass
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon 🔐
# @raycast.argument1 { "type": "text", "placeholder": "Path (e.g Email/zx2c4.com)" }
# @raycast.argument2 { "type": "text", "placeholder": "Password", "secure": true, "optional": true }
# @raycast.packageName Utils
# Documentation:
# @raycast.description Unix pass password manager integration for Raycast
# @raycast.author Khasbilegt.TS
# @raycast.authorURL https://github.com/khasbilegt
import subprocess
import sys
from pathlib import Path
PASSWORD_STORE_PATH = Path("~/.password-store").expanduser()
PASSWORD_PATH = (PASSWORD_STORE_PATH / Path(f"{sys.argv[1]}.gpg")).resolve()
def execute_command(args, capture_output=True):
return subprocess.run(args, check=True, text=True, capture_output=capture_output)
if PASSWORD_PATH.exists():
try:
password_args = [
"--pinentry-mode",
"loopback",
"--passphrase",
f"{sys.argv[2]}",
]
content = execute_command(
[
"gpg",
"--decrypt",
*(password_args if sys.argv[2] else []),
f"{PASSWORD_PATH}",
]
)
copied = execute_command(["pass", "-c", f"{sys.argv[1]}"])
print(f"🔑 {content.stdout}")
print(f"🤖 {copied.stdout}")
except subprocess.CalledProcessError as e:
print("Couldn't decrypt the file!")
else:
execute_command(["pass"], capture_output=False)
print(f"\nNot found: {sys.argv[1]}")