Permalink
Browse files

Set $HOME up front, like other environment variables.

If it wasn't already set, it would be evaluated on every ~.
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 2, 2018
1 parent 8b6c8c5 commit 45bdc29b6a39bb6d0c28da26f7af94ee56a20082
Showing with 8 additions and 9 deletions.
  1. +5 −0 core/state.py
  2. +3 −9 core/word_eval.py
View
@@ -417,6 +417,11 @@ def _InitVarsFromEnv(self, environ):
ast.LhsName('SHELLOPTS'), None, (var_flags_e.ReadOnly,),
scope_e.GlobalOnly)
v = self.GetVar('HOME')
if v.tag == value_e.Undef:
home_dir = util.GetHomeDir() or '~' # No expansion if not found?
SetGlobalString(self, 'HOME', home_dir)
def SetSourceLocation(self, source_name, line_num):
# Mutate Str() objects.
self.source_name.s = source_name
View
@@ -176,16 +176,10 @@ def _EvalTildeSub(self, prefix):
if prefix == '':
# First look up the HOME var, and then env var
val = self.mem.GetVar('HOME')
if val.tag == value_e.Str:
return val.s
elif val.tag == value_e.StrArray:
raise AssertionError
s = util.GetHomeDir()
if s is None:
s = '~' + prefix # No expansion I guess
return s
assert val.tag == value_e.Str, val
return val.s
# For ~otheruser/src. TODO: Should this be cached?
# http://linux.die.net/man/3/getpwnam
try:
e = pwd.getpwnam(prefix)

0 comments on commit 45bdc29

Please sign in to comment.