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
🔖 Lemnos: A simple, light-weight command-line to-do list manager.

🔖 Lemnos: CLI To-do List Manager This is a simple program that allows one to manage a to-do list via the command-line. Example $ python3 todo.py add

Rohan Sikand 1 Dec 07, 2022
Salesforce object access auditor

Salesforce object access auditor Released as open source by NCC Group Plc - https://www.nccgroup.com/ Developed by Jerome Smith @exploresecurity (with

NCC Group Plc 90 Sep 19, 2022
A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

Tom Dörr 976 Jan 03, 2023
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

18.6k Dec 30, 2022
PdpCLI is a pandas DataFrame processing CLI tool which enables you to build a pandas pipeline from a configuration file.

PdpCLI Quick Links Introduction Installation Tutorial Basic Usage Data Reader / Writer Plugins Introduction PdpCLI is a pandas DataFrame processing CL

Yasuhiro Yamaguchi 15 Jan 07, 2022
ICMP Reverse Shell written in Python 3 and with Scapy (backdoor/rev shell)

icmpdoor - ICMP Reverse Shell icmpdoor is an ICMP rev shell written in Python3 and scapy. Tested on Ubuntu 20.04, Debian 10 (Kali Linux), and Windows

Jeroen van Kessel 206 Dec 29, 2022
Python Command Line Application (CLI) using Typer, SQLModel, Async-PostgrSQL, and FastAPI

pyflycli is a command-line interface application built with Typer that allows you to view flights above your location.

Kevin Zehnder 14 Oct 01, 2022
a-shell: A terminal for iOS, with multiple windows

a-shell: A terminal for iOS, with multiple windows

Nicolas Holzschuch 1.7k Jan 02, 2023
Project scoped command execution to just do your work

Judoka is a command line utility that lets you define project scoped commands and call them through their alias. It lets you just do (= judo) your work.

Eelke van den Bos 2 Dec 17, 2021
bsp_tool provides a Command Line Interface for analysing .bsp files

bsp_tool Python library for analysing .bsp files bsp_tool provides a Command Line Interface for analysing .bsp files Current development is focused on

Jared Ketterer 64 Dec 28, 2022
Bringing emacs' greatest feature to neovim - Tetris!

nvim-tetris Bringing emacs' greatest feature to neovim - Tetris! This plugin is written in Fennel using Olical's project Aniseed for creating the proj

129 Dec 26, 2022
Custom 64 bit shellcode encoder that evades detection and removes some common badchars (\x00\x0a\x0d\x20)

x64-shellcode-encoder Custom 64 bit shellcode encoder that evades detection and removes some common badchars (\x00\x0a\x0d\x20) Usage Using a generato

Cole Houston 2 Jan 26, 2022
Analysis of a daily word game "Wordle"

Wordle Analysis of a daily word game "Wordle" https://www.powerlanguage.co.uk/wordle/ Description Worlde is a daily word game in which a player attemp

Bartek 1 Feb 07, 2022
A dec-bin converter uses 2's complement.

2's Complement Dec-Bin Converter A dec-bin converter uses 2's complement. Visit my Medium Post. What is 2's complement? Two's complement is the most c

Khaw Chi Hun (Jacky) 9 Mar 01, 2022
uploadgram uses your Telegram account to upload files up to 2GiB, from the Terminal.

uploadgram uploadgram uses your Telegram account to upload files up to 2GiB, from the Terminal. Heavily inspired by the telegram-upload Installing: pi

Shrimadhav U K 97 Jan 06, 2023
Redial is a simple shell application that manages your SSH sessions on Unix terminal.

redial redial is a simple shell application that manages your SSH sessions on Unix terminal. What's New 0.7 (19.12.2019) Basic support for adding ssh

Bahadır Yağan 186 Oct 28, 2022
Pequeno joguinho pra você rodar no seu terminal

JokenPython Pequeno joguinho pra você rodar no seu terminal Olá! Joguinho legal pra vc rodar no seu terminal!! (rode no terminal, pra melhor experienc

Scott 4 Nov 25, 2021
A simple CLI tool for getting region-specific status of Logz.io components.

About A simple CLI tool for checking the current status of Logz.io components per region. Built With Python 3 The following packeges (see requirements

Yotam Bernaz 1 Dec 11, 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
Access hacksec.in from your command-line

Access hacksec.in from your command-line

hacksec.in 3 Oct 26, 2022