XDG updates

This commit is contained in:
Anthony Scopatz 2015-08-05 15:19:03 -05:00
parent 810ca4302d
commit aa5198edc3
3 changed files with 34 additions and 7 deletions

View file

@ -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 ``${}``

View file

@ -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

View file

@ -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