def _EvalTildeSub(self, prefix): """Evaluates ~ and ~user. Args: prefix: The tilde prefix (possibly empty) """ 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 # http://linux.die.net/man/3/getpwnam try: e = pwd.getpwnam(prefix) except KeyError: s = '~' + prefix else: s = e.pw_dir return s
def InitReadline(complete_cb): 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) except IOError: pass atexit.register(readline.write_history_file, history_filename) readline.parse_and_bind("tab: complete") # How does this map to C? # https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC45 readline.set_completer(complete_cb) # NOTE: This apparently matters for -a -n completion -- why? Is space the # right value? # http://web.mit.edu/gnu/doc/html/rlman_2.html#SEC39 # "The basic list of characters that signal a break between words for the # completer routine. The default value of this variable is the characters # which break words for completion in Bash, i.e., " \t\n\"\\'`@$><=;|&{("" # # Hm I don't get this. readline.set_completer_delims(' ')
def _InitVarsFromEnv(self, environ): # This is the way dash and bash work -- at startup, they turn everything in # 'environ' variable into shell variables. Bash has an export_env # variable. Dash has a loop through environ in init.c for n, v in environ.iteritems(): self.SetVar(ast.LhsName(n), runtime.Str(v), (var_flags_e.Exported, ), scope_e.GlobalOnly) # If it's not in the environment, initialize it. This makes it easier to # update later in ExecOpts. # TODO: IFS, PWD, etc. should follow this pattern. Maybe need a SysCall # interface? self.syscall.getcwd() etc. v = self.GetVar('SHELLOPTS') if v.tag == value_e.Undef: SetGlobalString(self, 'SHELLOPTS', '') # Now make it readonly self.SetVar(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)