diff --git a/docs/tutorial.rst b/docs/tutorial.rst index e3ed5c008..78e9188fa 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -240,6 +240,12 @@ XONSH_SHOW_TRACEBACK Not defined Controls if a traceback CASE_SENSITIVE_COMPLETIONS True on Linux otherwise False Sets whether completions should be case sesistive or case insensitive. +XONSH_DATA_DIR $XDG_DATA_HOME/xonsh This is the location where + xonsh data files are stored, + such as history. +XONSH_CONFIG_DIR $XDG_CONFIG_HOME/xonsh This is location where xonsh + configuration information is + stored. ========================== ============================= ================================ Environment Lookup with ``${}`` diff --git a/xonsh/environ.py b/xonsh/environ.py index c142aa7aa..5ae10db0e 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -523,6 +523,19 @@ def xonshrc_context(rcfile=None, execer=None): return env +def recursive_base_env_update(env): + """Updates the environment with members that may rely on previously defined + members. Takes an env as its argument. + """ + home = os.path.expanduser('~') + if 'XONSH_DATA_DIR' not in env: + xdgdh = env.get('XDG_DATA_HOME', os.path.join(home, '.local', 'share')) + env['XONSH_DATA_DIR'] = os.path.join(xdgdh, 'xonsh') + if 'XONSH_CONFIG_DIR' not in env: + xdgch = env.get('XDG_CONFIG_HOME', os.path.join(home, '.config')) + env['XONSH_CONFIG_DIR'] = os.path.join(xdgch, 'xonsh') + + def default_env(env=None): """Constructs a default xonsh environment.""" # in order of increasing precedence @@ -548,7 +561,8 @@ def default_env(env=None): del ctx[ev] ctx['PWD'] = _get_cwd() - + # finalize env + recursive_base_env_update(ctx) if env is not None: ctx.update(env) return ctx diff --git a/xonsh/history.py b/xonsh/history.py index c3a543081..8046d9b75 100644 --- a/xonsh/history.py +++ b/xonsh/history.py @@ -12,13 +12,20 @@ from xonsh import lazyjson class History(object): - ordered_history = [] + def __init__(self, filename=None, sessionid=None, buffersize=100): + """Represents a xonsh session's history as an in-memory buffer that is + periodically flushed to disk. - def __init__(self, hid=None): - #env = builtins.__xonsh_env__ - #self.hf = env.get('XONSH_HISTORY_FILE', - # os.path.expanduser('~/.xonsh_history.json')) - self.hf = '~/.xonsh-history-{0}.json'.format(uuid.uuid4()) + Parameters + ---------- + filename : str, optional + + """ + self.sessionid = uuid.uuid4() if sessionid is None else sessionid + self.filename = '~/xonsh-{0}.json'.format(self.sessionid) \ + if filename is None else filename + self.buffer = [] + self.buffersize = buffersize def open_history(self): """Loads previous history from ~/.xonsh_history.json or