Skip to main content

The bar theme for xonsh shell.

Project description

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': '{env_name#strip_brackets#section}{gitstatus#nocolorx#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} {gitstatus#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}{gitstatus#nocolorx#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':      '{env_name#strip_brackets#section}{gitstatus#nocolorx#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
$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}{screens#section}{env_name#strip_brackets#section}{date_time_tz}'
xontrib load cmd_done

Additional links

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xontrib-prompt-bar-0.4.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

xontrib_prompt_bar-0.4.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file xontrib-prompt-bar-0.4.2.tar.gz.

File metadata

  • Download URL: xontrib-prompt-bar-0.4.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for xontrib-prompt-bar-0.4.2.tar.gz
Algorithm Hash digest
SHA256 479ed0e872536396ed4da052d19eb86484e8e0412837bd7b3616e58522571362
MD5 66d9e0fba9016c1af2d1a2484096498c
BLAKE2b-256 2346cb034997896167d24219d22d2441cdcadbd612fcb4b8fa63c4f00e31115e

See more details on using hashes here.

File details

Details for the file xontrib_prompt_bar-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xontrib_prompt_bar-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c49f6560db6ae3444716a137ae51ce0a304d726fa419eb3dce161fbbb6fcd0fd
MD5 d19e90f07ed84813a2822c852917741a
BLAKE2b-256 ad1f290d792c5e60fb58157350e62d675f3e1ceee8749fa8b1a917289eafa6f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page