Skip to main content

Yet another bash/zsh custom prompt script

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Issues

jwodder-ps1 is yet another program for Git-aware customization of the command prompt in Bash and zsh. Unlike all the others, I wrote this one, so it’s better.

https://github.com/jwodder/ps1.py/raw/master/screenshot.png

Features:

  • Lets you know if you have mail in $MAIL

  • Shows chroot, virtualenv, and Conda environment prompt prefixes

  • Automatically truncates the current directory path if it gets too long

  • Shows the status of the current Git repository (see below)

  • Supports both Bash and zsh

  • Can optionally output just the Git status, in case you want to combine it with your own prompt string

Installation & Setup

jwodder-ps1 requires Python 3.10 or higher. You’ll also need a Bash or zsh shell to set the program up in, and you’ll need git v1.7.10+ installed in order to get status information about Git repositories.

Install the jwodder-ps1 command by using pip or similar (using pipx is recommended) to install the package of the same name from PyPI.

If you use Bash, configure it to use jwodder-ps1 for the prompt by adding the following line to the end of your ~/.bashrc:

PROMPT_COMMAND="$PROMPT_COMMAND"'; PS1="$(jwodder-ps1 "${PS1_GIT:-}")"'

If you use zsh instead, add the following to the end of your ~/.zshrc:

precmd_jwodder_ps1() { PS1="$(jwodder-ps1 --zsh "${PS1_GIT:-}")" }
precmd_functions+=( precmd_jwodder_ps1 )

If you want to use just the Git status portion of the script’s output and combine it with your own prompt string, replace the PS1 assignment with your desired prompt, with $(jwodder-ps1 --git-only "${PS1_GIT:-}") inserted where you want the Git status string.

Depending on how jwodder-ps1 was installed and what the value of your PATH is, you may have to use the full path to the jwodder-ps1 executable instead.

Once jwodder-ps1 is configured, open a new shell and enjoy!

If the Git integration causes you trouble (either because something breaks or just because it’s taking too long to run), it can be temporarily disabled by running PS1_GIT=off on the command line.

Usage

jwodder-ps1 [<options>] [<git flag>]

The jwodder-ps1 command outputs a single line containing a stylized prompt string for the current directory. By default, the stylization is in a format usable in Bash’s PS1 variable, though the --ansi and --zsh option can be supplied to change the format.

jwodder-ps1 takes a single optional argument. If this argument is “off”, then the Git integration is disabled. If it is any other value or not specified, the Git integration is enabled.

Options

--ansi

Format output for direct display

--bash

Format output for use in Bash’s PS1 (default)

-G, --git-only

Only output the Git status string (including leading separator); output an empty line if not in a Git repository or if “off” is given on the command line

--git-timeout SECONDS

If running git status takes longer than the given number of seconds (default: 3), disable the Git integration

--no-hostname

Do not include the local hostname in the prompt string

-T THEME, --theme THEME

Select the theme to use for coloring prompt elements. The available themes are dark (the default, for use with light text on dark backgrounds) and light (for use with dark text on light backgrounds).

--username

Include the user’s login name in the prompt string

--zsh

Format output for use in zsh’s PS1

-V, --version

Display version information and exit

-h, --help

Display usage information and exit

Git Status Symbols

When inside a Git repository, a number of symbols showing the current HEAD and its status are added near the end of the prompt. Except for the @ separator and the HEAD itself, individual symbols are omitted when not relevant. From left to right, the symbols are:

  • @ — separator

  • + (bold light yellow) — Indicates there are stashed changes

  • The name of the HEAD (light green): the name of the current branch (if any), or the name of the currently checked-out tag (if any), or the short form of the current commit hash. This is light blue when the repository is in a detached HEAD state.

    This string is truncated if it gets too long.

  • +n (green) — how many commits HEAD is ahead of upstream

  • -n (red) — how many commits HEAD is behind upstream

  • * — Indicates whether there are any staged or unstaged changes in the working tree:

    • Green: There are staged changes

    • Red: There are unstaged changes

    • Bold light yellow: There are both staged and unstaged changes

  • + (bold red) — Indicates there are untracked files in the working tree

  • [STATE] (magenta) — Shows what activity Git is currently in the middle of, if any:

    • [BSECT] — bisecting

    • [CHYPK] — cherry-picking

    • [MERGE] — merging

    • [REBAS] — rebasing

    • [REVRT] — reverting

  • ! (bold red) — Indicates there are paths with merge conflicts

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

jwodder_ps1-0.8.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jwodder_ps1-0.8.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file jwodder_ps1-0.8.0.tar.gz.

File metadata

  • Download URL: jwodder_ps1-0.8.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for jwodder_ps1-0.8.0.tar.gz
Algorithm Hash digest
SHA256 c742a6b6ab38ab46e895aec46538ccc5a22a54fc85b343b50e0bbbdccec89dc6
MD5 cd3de9c2e720988e4ee4117c784d593b
BLAKE2b-256 4d9dfa5a0c73ff5bc7908e654e8e8c03e79e142b87add38a5ed7cc32ea73d7e9

See more details on using hashes here.

File details

Details for the file jwodder_ps1-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: jwodder_ps1-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for jwodder_ps1-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e771a4f3382b579e27da7a8ddc6b03721b82cb9b5a4d53837cf54f21115bc4a1
MD5 a8644c39e1a6e7d778a5391651047bef
BLAKE2b-256 6021f4b9aa790aefc8d20a99704a4c824c1a2686e9a66082b5913d0bb888d494

See more details on using hashes here.

Supported by

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