|
6 | 6 |
|
7 | 7 | import json
|
8 | 8 | import os
|
| 9 | +import re |
| 10 | +import shlex |
9 | 11 | import struct
|
10 | 12 | import subprocess
|
11 | 13 | import sys
|
@@ -52,6 +54,24 @@ def sendMessage(encodedMessage):
|
52 | 54 | sys.stdout.flush()
|
53 | 55 |
|
54 | 56 |
|
| 57 | +def setPassGpgOpts(env, opts_dict): |
| 58 | + """ Add arguments to PASSWORD_STORE_GPG_OPTS. """ |
| 59 | + opts = env.get('PASSWORD_STORE_GPG_OPTS', '') |
| 60 | + for opt, value in opts_dict.items(): |
| 61 | + re_opt = new_opt = opt |
| 62 | + if value is not None: |
| 63 | + re_opt = rf"{opt}(?:=|\s+)\S*" |
| 64 | + new_opt = ( |
| 65 | + f"{opt}={shlex.quote(value)}" |
| 66 | + if opt.startswith("--") else |
| 67 | + f"{opt} {shlex.quote(value)}" |
| 68 | + ) |
| 69 | + # If the user's environment sets this opt, remove it. |
| 70 | + opts = re.sub(re_opt, '', opts) |
| 71 | + opts = f"{new_opt} {opts}" |
| 72 | + env['PASSWORD_STORE_GPG_OPTS'] = opts.strip() |
| 73 | + |
| 74 | + |
55 | 75 | if __name__ == "__main__":
|
56 | 76 | # Read message from standard input
|
57 | 77 | receivedMessage = getMessage()
|
@@ -93,6 +113,7 @@ def sendMessage(encodedMessage):
|
93 | 113 | env["HOME"] = os.path.expanduser('~')
|
94 | 114 | for key, val in COMMAND_ENV.items():
|
95 | 115 | env[key] = val
|
| 116 | + setPassGpgOpts(env, {'--status-fd': '2', '--debug': 'ipc'}) |
96 | 117 |
|
97 | 118 | # Set up subprocess params
|
98 | 119 | cmd = [COMMAND] + opt_args + ['--'] + pos_args
|
|
0 commit comments