Yet another bash/zsh prompt script

Overview

Here we have yet another script for Git-aware customization of the command prompt in Bash and zsh. Unlike all the other scripts, I wrote this one, so it's better.

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)
  • thoroughly documented and easily customizable
  • supports both Bash and zsh
  • can optionally output just the Git status, in case you want to combine it with your own prompt string

Requirements

  • Python 3, version 3.5 or higher
  • Git, version 1.7.10 or higher
  • bash or zsh

Installation & Setup

  1. Save ps1.py to your computer somewhere (I put my copy at ~/share/ps1.py)

  2. If using Bash, add the following line to the end of your ~/.bashrc:

    PROMPT_COMMAND="$PROMPT_COMMAND"'; PS1="$(/usr/bin/python3 ~/share/ps1.py "${PS1_GIT:-}")"'

    If using zsh, add the following to the end of your ~/.zshrc:

    precmd_ps1_py() { PS1="$(/usr/bin/python3 ~/share/ps1.py --zsh "${PS1_GIT:-}")" }
    precmd_functions+=( precmd_ps1_py )

    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 $(/usr/bin/python3 ~/share/ps1.py --git-only "${PS1_GIT:-}") inserted where you want the Git status string.

    Replace /usr/bin/python3 with the path to your Python 3 interpreter, and replace ~/share/ps1.py with the location you saved ps1.py at as appropriate.

  3. Open a new shell

  4. Enjoy!

  5. 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

python3 ps1.py [<options>] [<git flag>]

ps1.py 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.

ps1.py 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
--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; turns light blue when the repository is in detached HEAD state
  • +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
You might also like...
A Python-based command prompt concept which includes windows command emulation.

PythonCMD A Python-based command prompt concept which includes windows command emulation. Current features: echo: Input your message and it will be cl

Powerful yet easy command line calculator.
Powerful yet easy command line calculator.

Powerful yet easy command line calculator.

Another (unofficial) Qt CLI Installer on multi-platforms

Another Qt installer(aqt) Release: Documentation: Test status: and Coverage: This is a utility alternative to the official graphical Qt installer, for

Command line tool to automate transforming the effects of one color profile to another, possibly more standard one.
Command line tool to automate transforming the effects of one color profile to another, possibly more standard one.

Finished rendering the frames of that animation, and now the colors look washed out and ugly? This terminal program will solve exactly that.

The Pythone Script will generate a (.)sh file with reverse shell codes then you can execute the script on the target

Pythone Script will generate a (.)sh file with reverse shell codes then you can execute the script on the targetPythone Script will generate a (.)sh file with reverse shell codes then you can execute the script on the target

A simple python script to execute a command when a YubiKey is disconnected

YubiKeyExecute A python script to execute a command when a YubiKey / YubiKeys are disconnected. ‏‏‎ ‎ How to use: 1. Download the latest release and d

A python script that enables a raspberry pi sd card through the CLI and automates the process of configuring network details and ssh.

This project is one script (wpa_helper.py) written in python that will allow for the user to automate the proccess of setting up a new boot disk and configuring ssh and network settings for the pi

git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's partial clone and sparse checkout features.

Partial Submodules for Git git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's

🌌 A Python script to generate blog banners from command line.
🌌 A Python script to generate blog banners from command line.

Auto Blog Banner Generator A Python script to generate blog banners. This script is used at RavSam. The following image is an example of the blog bann

Comments
  • Add option for escaping/not escaping escape characters

    Add option for escaping/not escaping escape characters

    Add a command-line option for controlling whether the script emits actual ESC characters (and any other control characters that may occur in strings) or instead emits C-style escape sequences (e.g., \e).

    wontfix 
    opened by jwodder 1
  • Escape backslashes in strings

    Escape backslashes in strings

    Escape any backslashes and control characters (especially ESC) that may occur in the host name, user name, current working directory, Git branch name, etc. so that bash doesn't choke.

    opened by jwodder 0
  • Shorten prompt if it gets too long

    Shorten prompt if it gets too long

    If the entire prompt string (not just the current directory) gets too long, shorten it, starting with the current directory path and the Git branch name.

    opened by jwodder 0
Releases(v0.5.0)
Owner
John T. Wodder II
John T. Wodder II
Gitfetch is a simple tool to get github user details

Gitfetch Just a (cli?) tool to get github user details 🙂 Installation 📂 Install Gitfetch via pypi pip install gitfetch or pip install git+https://g

I'm Not A Bot #Left_TG 7 Jan 23, 2022
Play Wordle Bot - Wordle Bot written in python

Wordle Bot A Bot written in python with a CL Interface to guess adn solve Wordle

Prashant 1 Feb 25, 2022
A simple command line chat app to communicate via the terminal.

A simple command line chat app to communicate via the terminal. I'm new to networking so sorry if some of my terminology or code is messed up.

PotNoodle 1 Oct 26, 2021
A lightweight terminal-based password manager coded with Python using SQLCipher for SQLite database encryption.

password-manager A lightweight terminal-based password manager coded with Python using SQLCipher for SQLite database encryption. Screenshot Pre-requis

Leonardo de Araujo 15 Oct 15, 2022
PyArmor is a command line tool used to obfuscate python scripts

PyArmor is a command line tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

Dashingsoft 2k Jan 07, 2023
Display Images in your terminal with python

A python library to display images in the terminal

Pranav Baburaj 57 Dec 30, 2022
Jupyter notebook client in neovim

🪐 Jupyter-Nvim Read jupyter notebooks in neovim Note: The plugin is still in alpha stage 👾 Usage Just open any *.ipynb file and voila! ✨ Contributin

Ahmed Khalf 85 Dec 29, 2022
command line interface to manage VALORANT skins

A PROPER RELEASE IS COMING SOON, IF YOU KNOW HOW TO USE PYTHON YOU CAN USE IT NOW! valorant skin manager command line interface simple command line in

colinh 131 Dec 25, 2022
Tmux Based Dropdown Dashboard For Python

sextans It's a private configuration and an ongoing experiment while I use Archlinux. A simple drop down dashboard based on tmux. It includes followin

秋葉 4 Dec 22, 2021
Tidier - a simple command line tool that helps you make your files tidy up

Tidier - a simple command line tool that helps you make your files tidy up

AmirMohammad Hosseini Nasab 8 Aug 16, 2022
Low-Cost Open Source Ventilator or PAPR

Last updated 2020/04/19 Low-Cost Open-Source Ventilator-ish Device or PAPR NOTE: This is currently an independent project not affiliated with any comm

Johnny Lee 1.7k Dec 21, 2022
Command-line interface to PyPI Stats API to get download stats for Python packages

pypistats Python 3.6+ interface to PyPI Stats API to get aggregate download statistics on Python packages on the Python Package Index without having t

Hugo van Kemenade 140 Jan 03, 2023
frogtrade9000 - a command-line Rich client for the freqtrade REST API

frogtrade9000 - a command-line Rich client for the freqtrade REST API I found FreqUI too cumbersome and slow on my Raspberry Pi 400 when running multi

Robert Davey 79 Dec 02, 2022
a GUI app base on warp-cli for linux

warp cloudflare gui a GUI app base on warp-cli for linux Installation read warp-cli install doc. install warp-cli and register with $ warp-cli registe

Moein Aghamirzaei 58 Jan 01, 2023
Command line tool to keep track of your favorite playlists on YouTube and many other places.

Command line tool to keep track of your favorite playlists on YouTube and many other places.

Wolfgang Popp 144 Jan 05, 2023
A new kind of Progress Bar, with real time throughput, eta and very cool animations!

A new kind of Progress Bar, with real time throughput, eta and very cool animations!

Rogério Sampaio de Almeida 4.1k Jan 08, 2023
Enlighten Progress Bar is a console progress bar library for Python.

Overview Enlighten Progress Bar is a console progress bar library for Python. The main advantage of Enlighten is it allows writing to stdout and stder

Rockhopper Technologies 265 Dec 28, 2022
A collection of command-line interface games written in python

Command Line Interface Python Games Collection of some starter python game projects for beginners How to play these games Clone this repository git cl

Paras Gupta 7 Jun 06, 2022
:computer: tmux session manager. built on libtmux

tmuxp, tmux session manager. built on libtmux. We need help! tmuxp is a trusted session manager for tmux. If you could lend your time to helping answe

python utilities for tmux 3.6k Jan 01, 2023
Aurornis - The Command Line Program Test Helper

Aurornis - The Command Line Program Test Helper Aurornis is a small, yet powerful library designed to help testing command line programs. The name is

Jérôme Deuchnord 1 Mar 08, 2022