Expand environment variables in the shell option

See #6511 for discussion
This commit is contained in:
Kovid Goyal 2023-09-24 08:28:42 +05:30
parent 3d6c3a9979
commit 76c6f91685
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 16 additions and 2 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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.
'''
)

View file

@ -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