A new remote control command @env to change the default environment passed to newly created windows
Fixes #3529
This commit is contained in:
parent
0b428987b1
commit
89fd726e07
@ -11,6 +11,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
scrollback buffer onto the screen. Useful, for example, to restore
|
||||
the screen after showing completions below the shell prompt.
|
||||
|
||||
- A new remote control command :ref:`at_env` to change the default
|
||||
environment passed to newly created windows (:iss:`3529`)
|
||||
|
||||
- Linux: Fix binary kitty builds not able to load fonts in WOFF2 format
|
||||
(:iss:`3506`)
|
||||
|
||||
|
||||
49
kitty/rc/env.py
Normal file
49
kitty/rc/env.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from .base import (
|
||||
ArgsType, Boss, PayloadGetType, PayloadType, RCOptions, RemoteCommand,
|
||||
ResponseType, Window
|
||||
)
|
||||
|
||||
|
||||
class Env(RemoteCommand):
|
||||
|
||||
'''
|
||||
env+: dictionary of environment variables to values. Empty values cause the variable to be deleted.
|
||||
'''
|
||||
|
||||
short_desc = 'Change environment variables seen by future children'
|
||||
desc = (
|
||||
'Change the environment variables seen by processing in newly launched windows.'
|
||||
' Similar to the :opt:`env` option in kitty.conf, but affects running kitty instances.'
|
||||
' Empty values cause the environment variable to be removed.'
|
||||
)
|
||||
argspec = 'env_var1=val env_var2=val ...'
|
||||
|
||||
def message_to_kitty(self, global_opts: RCOptions, opts: Any, args: ArgsType) -> PayloadType:
|
||||
if len(args) < 1:
|
||||
self.fatal('Must specify at least one env var to set')
|
||||
env = {}
|
||||
for x in args:
|
||||
key, val = x.split('=', 1)
|
||||
env[key] = val
|
||||
return {'env': env}
|
||||
|
||||
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
|
||||
from kitty.child import default_env, set_default_env
|
||||
from kitty.utils import expandvars
|
||||
new_env = payload_get('env') or {}
|
||||
env = default_env().copy()
|
||||
for k, v in new_env.items():
|
||||
if v:
|
||||
env[k] = expandvars(v, env)
|
||||
else:
|
||||
env.pop(k, None)
|
||||
set_default_env(env)
|
||||
|
||||
|
||||
env = Env()
|
||||
Loading…
x
Reference in New Issue
Block a user