{"id":13638250,"url":"https://github.com/anki-code/xontrib-prompt-bar","last_synced_at":"2025-10-15T13:11:12.291Z","repository":{"id":46703903,"uuid":"260538389","full_name":"anki-code/xontrib-prompt-bar","owner":"anki-code","description":"The bar prompt for xonsh shell with customizable sections and Starship support.","archived":false,"fork":false,"pushed_at":"2025-02-17T14:19:07.000Z","size":185,"stargazers_count":50,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T11:11:09.911Z","etag":null,"topics":["cli","cmd","console","iterm2","iterm2-theme","prompt","python","shell","shell-theme","terminal","windows-terminal","xonsh","xonsh-prompt","xontrib"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anki-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"]}},"created_at":"2020-05-01T19:10:05.000Z","updated_at":"2025-03-28T03:22:38.000Z","dependencies_parsed_at":"2025-02-23T07:11:29.169Z","dependency_job_id":null,"html_url":"https://github.com/anki-code/xontrib-prompt-bar","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-prompt-bar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-prompt-bar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-prompt-bar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxontrib-prompt-bar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anki-code","download_url":"https://codeload.github.com/anki-code/xontrib-prompt-bar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478323,"owners_count":20945266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cmd","console","iterm2","iterm2-theme","prompt","python","shell","shell-theme","terminal","windows-terminal","xonsh","xonsh-prompt","xontrib"],"created_at":"2024-08-02T01:00:42.880Z","updated_at":"2025-10-15T13:11:12.189Z","avatar_url":"https://github.com/anki-code.png","language":"Python","funding_links":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"],"categories":["Prompts"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e  \n    The bar prompt for the \u003ca href=\"https://xon.sh\"\u003exonsh shell\u003c/a\u003e with customizable sections.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e  \n\u003cimg src='https://raw.githubusercontent.com/anki-code/xontrib-prompt-bar/master/static/Demo.png' alt='[Demo]'\u003e\n\u003csup\u003e\u003ci\u003eScreenshot made in \u003ca href=\"https://konsole.kde.org/\"\u003eKonsole\u003c/a\u003e with \u003ccode\u003e$XONSH_COLOR_STYLE = \"paraiso-dark\"\u003c/code\u003e.\u003c/i\u003e\u003c/sup\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e  \nIf you like the idea of bar theme click ⭐ on the repo and \u003ca href=\"https://twitter.com/intent/tweet?text=Nice%20xontrib%20for%20the%20xonsh%20shell!\u0026url=https://github.com/anki-code/xontrib-prompt-bar\" target=\"_blank\"\u003etweet\u003c/a\u003e.\n\u003c/p\u003e\n\nFeatures:\n\n* Zero dependencies. You don't need to install additional packages.\n\n* Clear concept. The bar is a delimiter and information panel. Three attention aspects: command line and path, output, sections with additional info.\n\n* The command beginning has fixed position to have a large command line every time and avoid mess of attention.\n\n* 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.\n\n* Full customization. Change colors, add sections with info you need easily with Python.\n\n\n## Install\n```python\nxpip install -U xontrib-prompt-bar\necho 'xontrib load prompt_bar' \u003e\u003e ~/.xonshrc\n# Reload xonsh\n```\n\n## Default theme\n\n```python\n$XONTRIB_PROMPT_BAR_THEME = {\n    'left': '{hostname}{user}{cwd_abs#accent}',\n    'right': '{hist_status#section}{curr_branch#section}{env_name#strip_brackets#section}{date_time_tz}',\n    'bar_bg': '{BACKGROUND_#323232}',\n    'bar_fg': '{#AAA}',\n    'section_bg': '{BACKGROUND_#444}',\n    'section_fg': '{#CCC}',\n    'accent_fg': '{BOLD_#DDD}',\n}\nxontrib load prompt_bar\n```\n\n## Use cases\n\n### Customize the fields\n\nSupported fields:\n* [xonsh default fields and colors notation](https://xon.sh/tutorial.html#customizing-the-prompt)\n* `screens` - list of the windows that created by [screen window manager](https://www.gnu.org/software/screen/manual/screen.html#Overview) i.e. `screen -S mywin`.\n* `cwd_abs` - current absolute path (`~` disabled).\n* `date_time_tz` - date and time with timezone i.e. `21-12-25 18:00:00-01`.\n* `hist_status` - show `hist off` if history disabled by [`history off`](https://xon.sh/tutorial_hist.html#off-action) command.\n\nTo customize the appearance of the fields on the bar you can use wrappers and chaining them:\n```python\n$XONTRIB_PROMPT_BAR_RIGHT = '{hostname#accent#section} {date_time_tz#nocolorx}'\nxontrib load prompt_bar\n```\nBuiltin wrappers:\n* `section` - add backlight for the text.\n* `accent` - bold font and lighter color.\n* `noesc` - remove the ANSI escape characters (colors).\n* `strip` - remove the white spaces in the begin and end.\n* `strip_brackets` - remove the white spaces in the begin and end and then remove the brackets `()[]{}` if the text begins from brackets.\n* `nonl` - replace the new line symbols to spaces.\n* `nocolorx` - remove the xonsh color tags i.e. `{RED}` or `{#00ff00}`.\n\nTo create your own fields and wrapper see the section below.\n\n### Add custom fields and wrappers\nHow to add two new fields called `my_left_custom` and `my_right_custom` and one new wrapper called `brackets`.\n```python\n$PROMPT_FIELDS['my_left_custom'] = 'Hello left!'\n$PROMPT_FIELDS['my_right_custom'] = lambda: '\u003e'*3 + ' {YELLOW}Hello right!'\n\n$XONTRIB_PROMPT_BAR_WRAPPERS = {\n    'brackets': lambda v: f'[{v}]'\n}\n\n$XONTRIB_PROMPT_BAR_LEFT = '{hostname}{user}{cwd_abs#accent}{my_left_custom#brackets}'\n$XONTRIB_PROMPT_BAR_RIGHT = '{my_right_custom#section}{env_name#strip_brackets#section}{date_time_tz}'\n\nxontrib load prompt_bar\n```\nResult:\n\n\u003cimg src='https://raw.githubusercontent.com/anki-code/xontrib-prompt-bar/master/static/Demo-custom.png' alt='[Demo custom fields]'\u003e\n\n### Themes and colors\n\nTo change the bar colors there is setting the theme:\n\n```python\n$XONTRIB_PROMPT_BAR_THEME = {\n    'left':       '{hostname}{user}{cwd_abs#accent}',\n    'right':      '{curr_branch#section}{env_name#strip_brackets#section}{date_time_tz}',\n    'bar_bg':     '{BACKGROUND_#FF0000}',\n    'bar_fg':     '{#AAA}',\n    'section_bg': '{BACKGROUND_#444}',\n    'section_fg': '{#CCC}',\n    'accent_fg':  '{BOLD_#DDD}',\n}\nxontrib load prompt_bar\n```\nTo choose the colors there is [HTML Color Picker](https://www.w3schools.com/colors/colors_picker.asp).\n\n### Using [Starship](https://github.com/starship/starship) cross-shell prompt to rendering right sections\n\n\"Barship\" using [xontrib-prompt-starship](https://github.com/anki-code/xontrib-prompt-starship):\n\n```python\n# First of all create a starship config to return sections in one line\nmkdir -p ~/.config \u0026\u0026 echo @(\"\"\"\n[character]\nsuccess_symbol = \"\"\nerror_symbol = \"\"\n[status]\nsymbol = \"\"\n[python]\nsymbol = \"py \"\n#[directory]\n#disabled = true\n\"\"\".strip()) \u003e ~/.config/starship_xonsh_right.toml\n\n# Then just add the starship bar to right\n$XONTRIB_PROMPT_STARSHIP_RIGHT_CONFIG = \"~/.config/starship_xonsh_right.toml\"\n$XONTRIB_PROMPT_STARSHIP_REPLACE_PROMPT = False\n$XONTRIB_PROMPT_BAR_RIGHT = '{starship_right#noesc#nonl#strip}'\nxontrib load prompt_starship prompt_bar\n```\n\nResult:\n\n\u003cimg src=\"https://raw.githubusercontent.com/anki-code/xontrib-prompt-bar/master/static/xontrib-prompt-bar-starship.png\" alt=\"Prompt bar with starship sections.\"\u003e\n\n### Using [xontrib-cmd-durations](https://github.com/jnoortheen/xontrib-cmd-durations)\n\nThe [xontrib-cmd-durations](https://github.com/jnoortheen/xontrib-cmd-durations) is to send notification once long-running command is finished and also show the execution time. Usage example:\n\n```python\n# Add `{long_cmd_duration}` section\n$XONTRIB_PROMPT_BAR_RIGHT = '{long_cmd_duration}{curr_branch#section}{screens#section}{env_name#strip_brackets#section}{date_time_tz}'\nxontrib load cmd_done\n```\n\n### Hide return code in special cases\n\nSometimes it's needed to hide the return code. In this case you can use `-8888` return code i.e.:\n\n```xsh\naliases['cdls'] = \"cd @($arg0) \u0026\u0026 @(lambda: -8888 if len(g`./*`) \u003e 100 else 0) \u0026\u0026 ls --group-directories-first -A --color\"\ncdls /\n# return code is 0 and `ls` command was executed and return code is not shown\ncdls /usr/sbin\n# return code is -8888 and `ls` command was NOT executed and return code is not shown\n```\n\n### Additional links\n* [Asynchronous section rendering](https://xon.sh/envvars.html#enable-async-prompt)\n* [xonsh default fields and colors notation](https://xon.sh/tutorial.html#customizing-the-prompt)\n* [Meaning of git status symbols](https://xon.sh/envvars.html#xonsh-gitstatus) (●×+⚑✓↑↓)\n* [Awesome example of rewriting the theme from Jonathan Slenders](https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/examples/prompts/fancy-zsh-prompt.py)\n* [Customization the colors in the input line](https://github.com/xonsh/xonsh/pull/3878#issuecomment-707982828)\n\n## Environment variables\n\n* `$XONTRIB_PROMPT_BAR_SHOW_RETURN` - show return code. Default `True`.\n\n## Known issues\n### Spaces in the copied and pasted command line\nPlease update [prompt_toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) \nto 3.0.7+ version via `python -m pip install -U prompt_toolkit`.\n\n## Credits \n* This package is the part of [rc-awesome](https://github.com/anki-code/xontrib-rc-awesome) - awesome snippets of code for xonshrc in xonsh shell.\n* This package is the part of [ergopack](https://github.com/anki-code/xontrib-ergopack) - the pack of ergonomic xontribs.\n* This package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxontrib-prompt-bar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanki-code%2Fxontrib-prompt-bar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxontrib-prompt-bar/lists"}