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
CLI Web-CAT interface for people who use VIM.

CLI Web-CAT CLI Web-CAT interface. Installation git clone https://github.com/phuang1024/cliwebcat cd cliwebcat python setup.py bdist_wheel sdist cd di

Patrick 4 Apr 11, 2022
vimBrain is a brainfuck-based vim-inspired esoteric programming language.

vimBrain vimBrain is a brainfuck-based vim-inspired esoteric programming language. vimBrainPy Currently, the only interpreter available is written in

SalahDin Ahmed 3 May 08, 2022
CLI utility to search and download torrents from major torrent sites

CLI Torrent Downloader About CLI Torrent Downloader provides convenient and quick way to search torrent magnet links (and to run associated torrent cl

x0r0x 86 Dec 19, 2022
Professor Wordlist is a free open source command line tool written in python

Professor Wordlist is a free open source command line tool written in python, With the aim of generating custom wordlists with a variety of unique parameters and functions providing many possibilitie

オークO A K Z E H オーク 1 Oct 28, 2021
Simple command line tool to train and deploy your machine learning models with AWS SageMaker

metamaker Simple command line tool to train and deploy your machine learning models with AWS SageMaker Features metamaker enables you to: Build a dock

Yasuhiro Yamaguchi 5 Jan 09, 2022
[WIP]An ani-cli like cli tool for movies and webseries

mov-cli A cli to browse and watch movies. Installation This project is a work in progress. However, you can try it out python git clone https://github

166 Dec 30, 2022
ServX | Bash Command as a Service

ServX | Bash Command as a Service Screenshots Instructions for running Run python3 servx.py. COMPATIBILITY TESTED ON ARCHLINUX(x64) & DEBIAN(x64) ONLY

ARPSyndicate 2 Mar 11, 2022
Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.

OpenCV on Wheels Pre-built CPU-only OpenCV packages for Python. Check the manual build section if you wish to compile the bindings from source to enab

OpenCV 3.2k Jan 04, 2023
Faza - Faza terminal, Faza help to beginners for pen testing

Faza terminal simple tool for pen testers Use small letter only for commands Don't use space after command 'help' for more information Installation gi

Ag3ntQ 5 Feb 20, 2022
dcargs is a tool for generating portable, reusable, and strongly typed CLI interfaces from dataclass definitions.

dcargs is a tool for generating portable, reusable, and strongly typed CLI interfaces from dataclass definitions.

Brent Yi 119 Jan 09, 2023
Chameleon is yet another PowerShell obfuscation tool designed to bypass AMSI and commercial antivirus solutions.

Chameleon is yet another PowerShell obfuscation tool designed to bypass AMSI and commercial antivirus solutions. The tool has been developed as a Python port of the Chimera project, by tokioneon_.

332 Dec 26, 2022
Neovim integration for Google Keep, built using gkeepapi

Gkeep.nvim Neovim integration for Google Keep, built using gkeepapi Requirements Neovim 0.5 Python 3.6+ A patched font (optional. Used for icons) Tabl

Steven Arcangeli 143 Jan 02, 2023
Command-line parsing library for Python 3.

Command-line parsing library for Python 3.

36 Dec 15, 2022
Colab-xterm allows you to open a terminal in a cell

colab-xterm Colab-xterm allows you to open a terminal in a cell. Usage Install package and load the extension !pip install git+https://github.com/popc

InfuseAI 194 Dec 29, 2022
Python commandline tool for remembering linux/terminal commands

ehh Remember linux commands Commandline tool for remembering linux/terminal commands. It stores your favorite commands in ~/ehh.json in your homedir a

56 Nov 10, 2022
CLI tool to view your VIT timetable from terminal anytime!

VITime CLI tool to view your timetable from terminal anytime! Table of contents Preview Installation PyPI Source code Updates Setting up Add timetable

16 Oct 04, 2022
A simple reverse shell in python

RevShell A simple reverse shell in python Getting started First, start the server python server.py Finally, start the client (victim) python client.py

Lojacopsen 4 Apr 06, 2022
Commandline Python app to Autodownload mediafire folders and files.

Commandline Python app to Autodownload mediafire folders and files.

Tharuk Renuja 3 May 12, 2022
A simple python application for running a CI pipeline locally

A simple python application for running a CI pipeline locally This app currently supports GitLab CI scripts

Tom Stowe 0 Jan 11, 2022
Tools hacking termux in the name ant-attack

Hello friends, I am ama.player0000. Web developer, software, Android command line (termux). (1)=Well, ant-attack tool is a tool to attack sites and disable them. (2)=You can use those CCTV servers, s

༺AMA.PLAYER༻ 1 Dec 17, 2021