Skip to content

Commit

Permalink
https://github.com/santagada/xontrib-powerline/pull/16
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaaaanquish committed Aug 17, 2019
1 parent 7307f7c commit 3a4626a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions xontrib/powerline.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ $PL_PARTS = 10
$PL_DEFAULT_PROMPT = 'short_cwd>rtns'
$PL_DEFAULT_RPROMPT = 'history>time'
$PL_DEFAULT_TOOLBAR = 'who>cwd>branch>virtualenv>full_proc'
$PL_DEFAULT_EXTRA_SEC = {}
$PL_EXTRA_SEC = { 'user': lambda: [' {user} ', 'WHITE', '#555'] } if 'PL_EXTRA_SEC' not in ${...} else $PL_EXTRA_SEC
$PL_COLORS = {
"time": ("BLACK", "#00adee"),
"who": ("BLACK", "#666666"),
"short_cwd": ("BLACK", "#50a0a0"),
"cwd": ("#00adee", "WHITE"),
"history": ("WHITE", "#333333"),
"venv": ("BLACK", "INTENSE_GREEN"),
}


if ptk_shell_type() == 'prompt_toolkit2':
$PTK_STYLE_OVERRIDES['bottom-toolbar'] = 'noreverse'
Expand Down Expand Up @@ -44,17 +55,17 @@ def register_sec(f):

@register_sec
def history():
return Section(' %d ' % len(__xonsh__.history), 'WHITE', '#333')
return Section(' %d ' % len(__xonsh__.history), *$PL_COLORS["history"])


@register_sec
def time():
return Section(strftime(' %H:%M '), 'WHITE', 'BLUE')
return Section(strftime(' %H:%M '), *$PL_COLORS["time"])


@register_sec
def short_cwd():
return Section(' {short_cwd} ', 'WHITE', '#333')
return Section(' {short_cwd} ', *$PL_COLORS["short_cwd"])


def compress_home(path):
Expand Down Expand Up @@ -87,7 +98,7 @@ def cwd():
ps = new_ps

ps_join = (' %s ' % $PL_SEP_THIN).join(ps)
return Section(' %s ' % ps_join, 'WHITE', '#333')
return Section(' %s ' % ps_join, *$PL_COLORS["cwd"])


@register_sec
Expand All @@ -99,7 +110,7 @@ def branch():
@register_sec
def virtualenv():
if $PROMPT_FIELDS['env_name']():
return Section(' 🐍 {env_name} ', 'INTENSE_CYAN', 'BLUE')
return Section(' 🐍 {env_name} ', *$PL_COLORS["venv"])


@register_sec
Expand Down Expand Up @@ -143,7 +154,7 @@ def full_proc():

@register_sec
def who():
return Section(' {user}@{hostname} ', 'WHITE', '#555')
return Section(' {user}@{hostname} ', *$PL_COLORS["who"])


def prompt_builder(var, right=False):
Expand All @@ -163,6 +174,8 @@ def prompt_builder(var, right=False):
for s in pre_sections:
# A section can be 2 things, a literal Section or a Function
# and Functions can either return a Section of None if they are not part of prompt
if type(s()) == list:
s = Section(*s())
if isinstance(s, Section):
sections.append(s)
else:
Expand All @@ -189,6 +202,14 @@ def prompt_builder(var, right=False):
return prompt


def add_section(new_sec):
for name, section in new_sec.items():
if not callable(section):
print('$PL_EXTRA_SEC[\'%s\'] must be a function that return a list' % name)
return
available_sections[name] = section


@alias
def pl_set_mode(args):
if len(args) != 1 or args[0] not in modes:
Expand Down Expand Up @@ -217,6 +238,7 @@ def pl_build_prompt():
if varname not in __xonsh__.env:
__xonsh__.env[varname] = __xonsh__.env[defname]

add_section($PL_EXTRA_SEC)
$PROMPT = prompt_builder($PL_PROMPT)
$BOTTOM_TOOLBAR = prompt_builder($PL_TOOLBAR)
$RIGHT_PROMPT = prompt_builder($PL_RPROMPT, True)
Expand Down

0 comments on commit 3a4626a

Please sign in to comment.