Skip to content

Commit

Permalink
new strategy to match git directory
Browse files Browse the repository at this point in the history
  • Loading branch information
santagada committed Mar 14, 2017
1 parent 356ab07 commit 5e292ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='xontrib-powerline',
version='0.3.1',
version='0.3.2',

description='Powerline for Xonsh shell',
long_description=long_description,
Expand Down
28 changes: 15 additions & 13 deletions xontrib/powerline.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,29 @@ def compress_home(path):

@register_sec
def cwd():
if $PROMPT_FIELDS['curr_branch']():
git_format = True
top_level = $(git rev-parse --show-toplevel).strip()
else:
git_format = False

cwd = compress_home($PWD)
ps = compress_home($PWD).strip(os.sep).split(os.sep)

ps = cwd.strip(os.sep).split(os.sep)
if git_format:
top_level = compress_home(top_level)
git_idx = len(top_level.strip(os.sep).split(os.sep)) - 1
ps[git_idx] = '{BLUE}' + ps[git_idx] + '{WHITE}'
if $PROMPT_FIELDS['curr_branch']():
prefix = $(git rev-parse --show-prefix).strip()
ni = -1 # the default is for empty prefix, which means the last directory is the root of the repository
if prefix != '': # this is the case that we are in a sub directory, so we try matching subdirectories
subs = prefix.rstrip(os.sep).split(os.sep)
for sub in reversed(subs):
if ps[ni] != sub:
ni = 0
break
ni -= 1
if ni != 0: # if ni ==0 subdirectory matching failed
ps[ni] = '{BLUE}%s{WHITE}' % ps[ni]

if len(ps) > $PL_PARTS:
new_ps = [ps[0]]
new_ps.append('…')
new_ps += ps[-($PL_PARTS-1):]
ps = new_ps

return Section(' '+(' ' + $PL_SEP_THIN + ' ').join(ps) + ' ', 'WHITE', '#333')
ps_join = (' %s ' % $PL_SEP_THIN).join(ps)
return Section(' %s ' % ps_join, 'WHITE', '#333')


@register_sec
Expand Down

0 comments on commit 5e292ed

Please sign in to comment.