Permalink
Browse files

Fix bug where 'osh -i' doesn't run without $HOME set.

  • Loading branch information...
Andy Chu
Andy Chu committed Mar 17, 2017
1 parent 46ea03b commit 0d48e07e57e75594e9c65437cc9c15eb385047d1
Showing with 30 additions and 13 deletions.
  1. +7 −1 core/completion.py
  2. +17 −0 core/util.py
  3. +4 −10 core/word_eval.py
  4. +2 −2 spec.sh
View
@@ -692,7 +692,13 @@ def __call__(self, word, state):
def InitReadline(complete_cb):
history_filename = os.path.join(os.environ['HOME'], 'oil_history')
home_dir = os.environ.get('HOME')
if home_dir is None:
home_dir = util.GetHomeDir()
if home_dir is None:
print("Couldn't find home dir in $HOME or /etc/passwd", file=sys.stderr)
return
history_filename = os.path.join(home_dir, 'oil_history')
try:
readline.read_history_file(history_filename)
View
@@ -23,6 +23,8 @@
# http://stackoverflow.com/questions/3467526/attaching-a-decorator-to-all-functions-within-a-class
import inspect
import os
import pwd
import sys
import types
@@ -33,6 +35,21 @@ def log(msg, *args):
print(msg, file=sys.stderr)
def GetHomeDir():
"""Get the user's home directory from the /etc/passwd.
Used by tilde expansion in word_eval.py and readline initialization in
completion.py.
"""
uid = os.getuid()
try:
e = pwd.getpwuid(uid)
except KeyError:
return None
else:
return e.pw_dir
class _EnumValue(object):
"""A unique name."""
def __init__(self, namespace, name, value):
View
@@ -3,15 +3,14 @@
"""
import glob
import os
import pwd
import re
from core import braces
from core import expr_eval # ArithEval
from core.glob_ import Globber, GlobEscape
from core.id_kind import Id, Kind, IdName, LookupKind
from core.value import Value
from core import util
from osh import ast_ as ast
bracket_op_e = ast.bracket_op_e
@@ -505,14 +504,9 @@ def _EvalTildeSub(self, prefix):
if defined:
return val
# If no env, fall back on /etc/passwd
uid = os.getuid()
try:
e = pwd.getpwuid(uid)
except KeyError:
s = '~' + prefix
else:
s = e.pw_dir
s = util.GetHomeDir()
if s is None:
s = '~' + prefix # No expansion I guess
return Value.FromString(s)
View
@@ -251,7 +251,7 @@ pipeline() {
}
explore-parsing() {
sh-spec tests/explore-parsing.test.sh --osh-failures-allowed 6 \
sh-spec tests/explore-parsing.test.sh --osh-failures-allowed 5 \
${REF_SHELLS[@]} $OSH "$@"
}
@@ -290,7 +290,7 @@ var-sub() {
}
var-num() {
sh-spec tests/var-num.test.sh --osh-failures-allowed 1 \
sh-spec tests/var-num.test.sh \
${REF_SHELLS[@]} $OSH "$@"
}

0 comments on commit 0d48e07

Please sign in to comment.