elevate: only pass env diff to keep notifications readable
This commit is contained in:
parent
971c8a988d
commit
0c6ea9cca2
|
|
@ -346,14 +346,22 @@ def handle(conn):
|
|||
|
||||
|
||||
def _wrap_with_env(cmd, env):
|
||||
"""Wrap a command with explicit env setup.
|
||||
"""Wrap a command with env vars that differ from the adapter's own env.
|
||||
|
||||
Produces: env -i K1=V1 K2=V2 ... bash -c 'original command'
|
||||
This ensures the command runs with exactly the caller's environment.
|
||||
Only exports the delta so the command string stays readable in
|
||||
superpowerd notifications. Vars that match the session env are
|
||||
already inherited.
|
||||
"""
|
||||
import shlex
|
||||
parts = ["env", "-i"]
|
||||
for k, v in sorted(env.items()):
|
||||
adapter_env = os.environ
|
||||
diff = {}
|
||||
for k, v in env.items():
|
||||
if adapter_env.get(k) != v:
|
||||
diff[k] = v
|
||||
if not diff:
|
||||
return cmd
|
||||
parts = ["env"]
|
||||
for k, v in sorted(diff.items()):
|
||||
parts.append(f"{k}={v}")
|
||||
parts.extend(["bash", "-c", cmd])
|
||||
return " ".join(shlex.quote(p) for p in parts)
|
||||
|
|
|
|||
Loading…
Reference in New Issue