Skip to main content

The bar prompt for the xonsh shell with customizable sections.

[Demo] Screenshot made in Konsole with $XONSH_COLOR_STYLE = "paraiso-dark".

If you like the idea of bar theme click ⭐ on the repo and tweet.

Features:

  • Zero dependencies. You don't need to install additional packages.

  • Clear concept. The bar is a delimiter and information panel. Three attention aspects: command line and path, output, sections with additional info.

  • The command beginning has fixed position to have a large command line every time and avoid mess of attention.

  • The sections placed to right but not in the same line as command and it allows you to copy the command and output without environmental disclosure.

  • Full customization. Change colors, add sections with info you need easily with Python.

Install

xpip install -U xontrib-prompt-bar
echo 'xontrib load prompt_bar' >> ~/.xonshrc
# Reload xonsh

Default theme

$XONTRIB_PROMPT_BAR_THEME = {
    'left': '{hostname}{user}{cwd_abs#accent}',
    'right': '{hist_status#section}{curr_branch#section}{env_name#strip_brackets#section}{date_time_tz}',
    'bar_bg': '{BACKGROUND_#323232}',
    'bar_fg': '{#AAA}',
    'section_bg': '{BACKGROUND_#444}',
    'section_fg': '{#CCC}',
    'accent_fg': '{BOLD_#DDD}',
}
xontrib load prompt_bar

Use cases

Customize the fields

Supported fields:

To customize the appearance of the fields on the bar you can use wrappers and chaining them:

$XONTRIB_PROMPT_BAR_RIGHT = '{hostname#accent#section} {date_time_tz#nocolorx}'
xontrib load prompt_bar

Builtin wrappers:

  • section - add backlight for the text.
  • accent - bold font and lighter color.
  • noesc - remove the ANSI escape characters (colors).
  • strip - remove the white spaces in the begin and end.
  • strip_brackets - remove the white spaces in the begin and end and then remove the brackets ()[]{} if the text begins from brackets.
  • nonl - replace the new line symbols to spaces.
  • nocolorx - remove the xonsh color tags i.e. {RED} or {#00ff00}.

To create your own fields and wrapper see the section below.

Add custom fields and wrappers

How to add two new fields called my_left_custom and my_right_custom and one new wrapper called brackets.

$PROMPT_FIELDS['my_left_custom'] = 'Hello left!'
$PROMPT_FIELDS['my_right_custom'] = lambda: '>'*3 + ' {YELLOW}Hello right!'

$XONTRIB_PROMPT_BAR_WRAPPERS = {
    'brackets': lambda v: f'[{v}]'
}

$XONTRIB_PROMPT_BAR_LEFT = '{hostname}{user}{cwd_abs#accent}{my_left_custom#brackets}'
$XONTRIB_PROMPT_BAR_RIGHT = '{my_right_custom#section}{env_name#strip_brackets#section}{date_time_tz}'

xontrib load prompt_bar

Result:

[Demo custom fields]

Themes and colors

To change the bar colors there is setting the theme:

$XONTRIB_PROMPT_BAR_THEME = {
    'left':       '{hostname}{user}{cwd_abs#accent}',
    'right':      '{curr_branch#section}{env_name#strip_brackets#section}{date_time_tz}',
    'bar_bg':     '{BACKGROUND_#FF0000}',
    'bar_fg':     '{#AAA}',
    'section_bg': '{BACKGROUND_#444}',
    'section_fg': '{#CCC}',
    'accent_fg':  '{BOLD_#DDD}',
}
xontrib load prompt_bar

To choose the colors there is HTML Color Picker.

Using Starship cross-shell prompt to rendering right sections

"Barship" using xontrib-prompt-starship:

# First of all create a starship config to return sections in one line
mkdir -p ~/.config && echo @("""
[character]
success_symbol = ""
error_symbol = ""
[status]
symbol = ""
""".strip()) > ~/.config/starship_xonsh_right.toml

# Then just add the starship bar to right
$XONTRIB_PROMPT_STARSHIP_RIGHT_CONFIG = "~/.config/starship_xonsh_right.toml"
$XONTRIB_PROMPT_STARSHIP_REPLACE_PROMPT = False
$XONTRIB_PROMPT_BAR_RIGHT = '{starship_right#noesc#nonl#strip}'
xontrib load prompt_starship prompt_bar

Result:

Prompt bar with starship sections.

Using xontrib-cmd-durations

The xontrib-cmd-durations is to send notification once long-running command is finished and also show the execution time. Usage example:

# Add `{long_cmd_duration}` section
$XONTRIB_PROMPT_BAR_RIGHT = '{long_cmd_duration}{curr_branch#section}{screens#section}{env_name#strip_brackets#section}{date_time_tz}'
xontrib load cmd_done

Hide return code in special cases

Sometimes it's needed to hide the return code. In this case you can use -8888 return code i.e.:

aliases['cdls'] = "cd @($arg0) && @(lambda: -8888 if len(g`./*`) > 100 else 0) && ls --group-directories-first -A --color"
cdls /
# return code is 0 and `ls` command was executed and return code is not shown
cdls /usr/sbin
# return code is -8888 and `ls` command was NOT executed and return code is not shown

Additional links

Environment variables

  • $XONTRIB_PROMPT_BAR_SHOW_RETURN - show return code. Default True.

Known issues

Spaces in the copied and pasted command line

Please update prompt_toolkit to 3.0.7+ version via python -m pip install -U prompt_toolkit.

Credits

Release files for xontrib-prompt-bar 0.5.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xontrib-prompt-bar 0.5.8
File Size Uploaded
xontrib_prompt_bar-0.5.8.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xontrib-prompt-bar 0.5.8
File Interpreter ABI Platform
xontrib_prompt_bar-0.5.8-py3-none-any.whl Python 3 none any Details

Total release size:15.3 kB

Release files / xontrib_prompt_bar-0.5.8.tar.gz

Download URL xontrib_prompt_bar-0.5.8.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f79e53aa2526facff44b64e46928325037b7239e7debf0369876fe4a91b455e0
BLAKE2b-256 checksum
How to use checksums
95bc0b65123db1c2328242a1a4907b08fdd88a009f83cddb9de581319dca853a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / xontrib_prompt_bar-0.5.8-py3-none-any.whl

Download URL xontrib_prompt_bar-0.5.8-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a61b9bfe2fece286ea639ed0ae8b22c2dc7aee9c1d3c1329ff1ece4a8153c5b
BLAKE2b-256 checksum
How to use checksums
10c040a3e695043e0d19ec0d26f87fe3b832a9ea199f0011501682818d0daae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.5.8 This release

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

0.0.4

1 release file

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page