Skip to content

Commit

Permalink
Allow custom environment variables with lazy.spawn
Browse files Browse the repository at this point in the history
Adds an `env` argument to `lazy.spawn` to pass a dictionary of
environmental variables for the child process.

Fixes qtile#4705
  • Loading branch information
elParaguayo authored and tych0 committed Feb 24, 2024
1 parent afa4dcb commit 4f5c303
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libqtile/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,9 @@ def validate_config(self) -> None:
send_notification("Configuration check", "No error found!")

@expose_command()
def spawn(self, cmd: str | list[str], shell: bool = False) -> int:
def spawn(
self, cmd: str | list[str], shell: bool = False, env: dict[str, str] = dict()
) -> int:
"""
Spawn a new process.
Expand All @@ -1236,6 +1238,8 @@ def spawn(self, cmd: str | list[str], shell: bool = False) -> int:
shell:
Whether to execute the command in a new shell by prepending it with "/bin/sh
-c". This enables the use of shell syntax within the command (e.g. pipes).
env:
Dictionary of environmental variables to pass with command.
Examples
========
Expand Down Expand Up @@ -1288,6 +1292,9 @@ def spawn(self, cmd: str | list[str], shell: bool = False) -> int:
except KeyError:
pass

for k, v in env.items():
os.environ[k] = v

# Open /dev/null as stdin, stdout, stderr
try:
fd = os.open(os.devnull, os.O_RDWR)
Expand Down

0 comments on commit 4f5c303

Please sign in to comment.