diff --git a/docs/changelog.rst b/docs/changelog.rst index 0052a0ee7..982ffcd0d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -52,6 +52,8 @@ Detailed list of changes - themes kitten: Allow absolute paths for ``--config-file-name`` (:iss:`6638`) +- Expand environment variables in the :opt:`shell` option (:iss:`6511`) + 0.30.0 [2023-09-18] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 75749d2c2..c37ddeb02 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -2782,7 +2782,7 @@ The shell program to execute. The default value of :code:`.` means to use whatever shell is set as the default shell for the current user. Note that on macOS if you change this, you might need to add :code:`--login` and :code:`--interactive` to ensure that the shell starts in interactive mode and -reads its startup rc files. +reads its startup rc files. Environment variables are expanded in this setting. ''' ) diff --git a/kitty/utils.py b/kitty/utils.py index c138ce336..2d0fe4ad3 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -771,7 +771,19 @@ def resolved_shell(opts: Optional[Options] = None) -> List[str]: ans = [shell_path] else: import shlex - ans = shlex.split(q) + env = {} + if opts is not None: + env['TERM'] = opts.term + if 'SHELL' not in os.environ: + env['SHELL'] = shell_path + if 'HOME' not in os.environ: + env['HOME'] = os.path.expanduser('~') + if 'USER' not in os.environ: + import pwd + env['USER'] = pwd.getpwuid(os.geteuid()).pw_name + def expand(x: str) -> str: + return expandvars(x, env) + list(map(expand, shlex.split(q))) return ans