Merge pull request #543 from adqm/collapsed_path

fish-style shortened cwd as short_cwd
This commit is contained in:
Anthony Scopatz 2015-11-30 15:49:48 -05:00
commit 7e137adc3d
2 changed files with 14 additions and 0 deletions

View file

@ -838,6 +838,8 @@ By default, the following variables are available for use:
* ``user``: The username of the current user
* ``hostname``: The name of the host computer
* ``cwd``: The current working directory
* ``short_cwd``: A shortened form of the current working directory; e.g.,
``/path/to/xonsh`` becomes ``/p/t/xonsh``
* ``cwd_dir``: The dirname of the current working directory, e.g. ``/path/to`` in
``/path/to/xonsh``.
* ``cwd_base``: The basename of the current working directory, e.g. ``xonsh`` in

View file

@ -58,6 +58,7 @@ DEFAULT_ENSURERS = {
'CASE_SENSITIVE_COMPLETIONS': (is_bool, to_bool, bool_to_str),
re.compile('\w*DIRS'): (is_env_path, str_to_env_path, env_path_to_str),
'COMPLETIONS_DISPLAY': (is_completions_display_value, to_completions_display_value, str),
'FORCE_POSIX_PATHS': (is_bool, to_bool, bool_to_str),
'HISTCONTROL': (is_string_set, csv_to_set, set_to_csv),
'IGNOREEOF': (is_bool, to_bool, bool_to_str),
'LC_COLLATE': (always_false, locale_convert('LC_COLLATE'), ensure_string),
@ -547,6 +548,16 @@ def _replace_home(x):
_replace_home_cwd = lambda: _replace_home(builtins.__xonsh_env__['PWD'])
def _collapsed_pwd():
sep = os.sep
if ON_WINDOWS and builtins.__xonsh_env__.get('FORCE_POSIX_PATHS'):
sep = os.altsep
pwd = _replace_home_cwd().split(sep)
l = len(pwd)
leader = sep if l>0 and len(pwd[0])==0 else ''
base = [i[0] if ix != l-1 else i for ix,i in enumerate(pwd) if len(i) > 0]
return leader + sep.join(base)
if ON_WINDOWS:
USER = 'USERNAME'
@ -561,6 +572,7 @@ FORMATTER_DICT = dict(
cwd=_replace_home_cwd,
cwd_dir=lambda: os.path.dirname(_replace_home_cwd()),
cwd_base=lambda: os.path.basename(_replace_home_cwd()),
short_cwd=_collapsed_pwd,
curr_branch=current_branch,
branch_color=branch_color,
**TERM_COLORS)