Bash prompt generator (PS1)

Build the prompt of your terminal piece by piece: user, machine, directory, time, Git branch, each in its colour. The tool writes the block for the end of ~/.bashrc, with the colour codes correctly wrapped in \[ \].

Pieces, in order

    Options
    Preview
    
        

    Sample values; the shades of the 16 colours depend on your terminal’s theme.

    For the end of ~/.bashrc
    
        

    To try it without changing anything: paste the block straight into a terminal. Closing the terminal undoes it. To keep it, add it at the end of ~/.bashrc (on macOS, ~/.bash_profile), then source ~/.bashrc.

    Good to know

    \[ … \]
    Tell bash that what is inside prints nothing. Without them, bash miscounts the width of the prompt, and long commands wrap over themselves. The tool puts them around every colour code.
    $(__rno_git)
    The Git branch piece runs git before each prompt. Instant in an ordinary repository; in a huge one or on a slow network drive, it can be felt.
    PROMPT_COMMAND
    The exit status piece puts a small function first in PROMPT_COMMAND, to catch the status before anything else runs. It keeps what is already there, and does not add itself twice if ~/.bashrc is read again.
    zsh
    macOS uses zsh by default since 2019: it ignores PS1 written for bash (its escapes are %n, %m, %~). This tool is for bash only.

    Transparency

    The prompt is composed in your browser, by the scripts listed below. Nothing you choose leaves this page.

    Enforced by your browser
    This page's Content Security Policy allows a single destination, the site's audience measurement (connect-src https://stats.r-no.fr, see below), and forbids any form submission (form-action 'none'), so even a bug could not send what you type anywhere. You can read the policy at the top of the page source.
    Audience measurement
    Like every page of the site, this one counts its visit with Umami, installed on R-no’s own server (stats.r-no.fr). It receives the address of the page, without parameters or anchor, the site you came from (its domain only), your browser, system, language and screen size, and the country, region and city deduced from your IP address, which is not kept. It never receives what you type, nor the result of the tool. No cookie, nothing stored in your browser; if your browser asks not to be tracked (Do Not Track), nothing is measured. The data is erased after 25 months.
    • /commun/mesure.js: the filter applied before each sending, written for R-no Toolbox. 1.4 kB
      SHA-256 225eec74fd12623d82fc05ee7d222be629ce454d081c129e8d1e249ed37ee716
    • https://stats.r-no.fr/m.js: Umami’s tracker, open source (MIT), served by the measurement server. Its fingerprint is not shown here: it changes with each version of Umami, and you cannot check from your browser that it is the published code. For that part, you have to trust R-no.
    What is stored
    No cookie, and nothing in the address. What you type is never stored: it disappears when you reload or close the page. Your language is given by the address itself (/en/ or /fr/): nothing is stored to remember it. Like any website, the server records the download of the page and its files in its access logs (IP address, date and time, address requested, browser name). It never receives what you type.
    Code that runs here
    • app.js: the composition of the prompt and its preview, written for R-no Toolbox. Not minified, no third-party library. 18.0 kB
      SHA-256 058fe99a8c7c171a5379d3e435d76e87a5cef89386600d644e84fccc99276375
    • textes.js: the French messages of the tool, shown by its script (the rest of the French page is written into its HTML when the site is built). It only defines texts, with no logic. 8.5 kB
      SHA-256 680bc47675e7884ab3e2a97deb7352a1ab72610881f00dfbe600488c96c5f456
    • /commun/langue.js: the language helper, the same on every page of the site. It reads the language of the page and gives the tool its messages in that language. It stores nothing. 1.6 kB
      SHA-256 80f76f69773ef628d36d09bf8387cfedebda4529210d7120649b6f5603310631
    Before you paste
    This page only writes text: it runs nothing, neither here nor on your machine. What you paste into a terminal or a configuration file runs with your rights, so read it first. The code it writes downloads nothing and calls no outside service.
    How it was checked
    Every model, and a text piece full of $, `, \ and quotes, was loaded into bash 5.2 and rendered with ${PS1@P}: the visible text matches the preview, and every escape sequence sits inside \[ \]. The blocks pass ShellCheck.
    Check it yourself
    Download a script and compare its fingerprint with the one above:
    curl -s https://r-no.fr/bash/ps1/app.js | shasum -a 256
    Limits
    Bash only (not zsh, fish or sh). The preview uses sample values and xterm’s shades. The Git branch piece needs git on the machine; the exit status piece relies on PROMPT_COMMAND, so keep the block after any line of ~/.bashrc that replaces it. The 16 basic colours only; for others, see bash/colors.