Permalink
Browse files

Add 'i' to $- when the shell is interactive.

Fixes issue #118.
  • Loading branch information...
Andy Chu
Andy Chu committed May 25, 2018
1 parent e5d373a commit 62f487267cc8d092487fa9c4fa2eee3b3c5479c8
Showing with 20 additions and 6 deletions.
  1. +5 −6 bin/oil.py
  2. +7 −0 core/state.py
  3. +8 −0 spec/sh-options.test.sh
View
@@ -262,23 +262,23 @@ def OshMain(argv0, argv, login_shell):
if opts.c is not None:
arena.PushSource('<command string>')
line_reader = reader.StringLineReader(opts.c, arena)
interactive = False
if opts.i: # -c and -i can be combined
exec_opts.interactive = True
elif opts.i: # force interactive
arena.PushSource('<stdin -i>')
line_reader = reader.InteractiveLineReader(OSH_PS1, arena)
interactive = True
exec_opts.interactive = True
else:
try:
script_name = argv[opt_index]
except IndexError:
if sys.stdin.isatty():
arena.PushSource('<interactive>')
line_reader = reader.InteractiveLineReader(OSH_PS1, arena)
interactive = True
exec_opts.interactive = True
else:
arena.PushSource('<stdin>')
line_reader = reader.FileLineReader(sys.stdin, arena)
interactive = False
else:
arena.PushSource(script_name)
try:
@@ -287,13 +287,12 @@ def OshMain(argv0, argv, login_shell):
util.error("Couldn't open %r: %s", script_name, os.strerror(e.errno))
return 1
line_reader = reader.FileLineReader(f, arena)
interactive = False
# TODO: assert arena.NumSourcePaths() == 1
# TODO: .rc file needs its own arena.
w_parser, c_parser = parse_lib.MakeParser(line_reader, arena)
if interactive:
if exec_opts.interactive:
# NOTE: We're using a different evaluator here. The completion system can
# also run functions... it gets the Executor through Executor._Complete.
if HAVE_READLINE:
View
@@ -104,6 +104,10 @@ def __init__(self, mem):
"""
self.mem = mem
# Depends on the shell invocation (sh -i, etc.) This is not technically an
# 'set' option, but it appears in $-.
self.interactive = False
# set -o / set +o
self.errexit = _ErrExit() # -e
self.nounset = False # -u
@@ -169,6 +173,9 @@ def ErrExit(self):
def GetDollarHyphen(self):
chars = []
if self.interactive:
chars.append('i')
if self.ErrExit():
chars.append('e')
if self.nounset:
View
@@ -20,6 +20,14 @@ echo $-
# N-I dash stdout-json: ""
# N-I dash status: 2
### $- with interactive shell
$SH -c 'echo $-' | grep i || echo FALSE
$SH -i -c 'echo $-' | grep -q i && echo TRUE
## STDOUT:
FALSE
TRUE
## END
### sh -c
$SH -c 'echo hi'
# stdout: hi

0 comments on commit 62f4872

Please sign in to comment.