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
3 changed files with 16 additions and 2 deletions

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