Live Preview
{{ params.elements.length }} element(s) Delimiter: {{ params.delimiter || ' ' }} Prefix Suffix

      
Prompt Elements
  • {{ elementLabel(el) }}
Element Properties
Appearance
Global Settings
Import Existing PS1
Parses common tokens, dates, variables, command substitutions, and newlines.
Preview Background
Git Helper Snippet

If you selected Git Branch, add this helper to your shell rc before setting PS1:

parse_git_branch() { git branch --show-current 2>/dev/null | awk 'NF{print " (" $0 ")"}'; }
Generated PS1

          
        
Element PS1 Snippet Copy
{{ r.label }} {{ r.snippet }}
No elements.

      

Introduction:

Stylized terminal window with prompt line.

Shell prompts in Bash are short status lines that appear before each command and they can show who you are where you are and the time. A custom Bash PS1 prompt helps you read context at a glance and reduces typing mistakes.

You select building blocks such as username host working directory clock exit code and a prompt character and you choose colours emphasis and backgrounds so the line stays legible. This makes a clear starting point for a custom Bash PS1 prompt.

You can import an existing PS1 string and the generator maps common tokens variables and command substitutions so you can adjust them quickly. Then you preview a sample with realistic values and copy a ready string for your shell configuration.

Test on both a dark background and a light background so colour choices remain readable. Avoid overly bright combinations and keep separators simple so the eye lands on the parts you check most.

If you include the Git branch add the helper function noted below so the branch name appears only when a repository is present.

Technical Details:

Bash prompt strings are templates evaluated before each command to produce context such as identity location and time. The primary template variable is PS1 which is a sequence of text plus backslash escapes and optional command or variable expansions.

The generator composes PS1 from chosen tokens and wraps nonprinting terminal control sequences so line editing and width calculations remain correct. Colours and text attributes are applied using ANSI Select Graphic Rendition codes with a reset after each token.

Results are interpreted by reading the visible parts of the prompt as quick cues. Colour and emphasis signal boundaries such as user versus host or path versus time, while the final character clarifies command status or privilege.

Comparisons across machines are meaningful when terminals support the same colour depth and when the same tokens are used in the same order. Values like username or path vary by session and are resolved at prompt time.

  1. Choose tokens and their order.
  2. Assign foreground and optional background colours.
  3. Toggle attributes such as bold dim italic underline blink reverse.
  4. Join tokens with a delimiter.
  5. Add optional prefix and suffix.
  6. Wrap each styled token with nonprinting open and reset sequences.
Symbols and units for common PS1 tokens
Symbol Meaning Unit/Datatype Source
\uUsernamestringDerived at prompt time
$(id -u)User IDnumber → stringDerived at prompt time
\hHostname shortstringDerived at prompt time
\HHostname fullstringDerived at prompt time
\wWorking directorypathDerived at prompt time
\WDirectory basenamepathDerived at prompt time
$(parse_git_branch)Git branch via helperstringDerived at prompt time
\vBash versionstringDerived at prompt time
\VShell releasestringDerived at prompt time
\sShell namestringDerived at prompt time
\dDate shortstringDerived at prompt time
\D{fmt}Date custom formatstringDerived at prompt time
\t, \A, \T, \@Times 24 h and 12 hstringDerived at prompt time
$VAREnvironment variablestringDerived at prompt time
\!History numbernumber → stringDerived at prompt time
\#Command numbernumber → stringDerived at prompt time
\jJobsnumber → stringDerived at prompt time
$?Exit statusnumber → stringDerived at prompt time
\$Prompt characterstringDerived at prompt time
\nNew linecontrolLiteral
textLiteral charactersstringLiteral
Worked example. Tokens: \u, @, \h, :, \w; delimiter is a space; suffix is $. With colours applied per token, the generated PS1 is:
$begin:math:display$\\e[38;2;0;255;0m$end:math:display$\u$begin:math:display$\\e[0m$end:math:display$ $begin:math:display$\\e[38;2;255;255;255m$end:math:display$@$begin:math:display$\\e[0m$end:math:display$ $begin:math:display$\\e[38;2;0;255;0m$end:math:display$\h$begin:math:display$\\e[0m$end:math:display$ $begin:math:display$\\e[38;2;255;255;255m$end:math:display$:$begin:math:display$\\e[0m$end:math:display$ $begin:math:display$\\e[38;2;0;128;255m$end:math:display$\w$begin:math:display$\\e[0m$end:math:display$ $
The visible preview resolves to something like alice@zeus:/home/alice/src/project $.

Variables and parameters

Core parameters
Parameter Meaning Datatype Typical Range Notes
prefixText placed before the promptstringOften empty or newlineEscaped safely
delimiterString between tokensstringSpace by defaultPreserves spacing
suffixText after the last tokenstring$ by defaultEscaped safely

ANSI colour and attributes

  • Colours use 24‑bit RGB via 38;2;r;g;b and backgrounds via 48;2;r;g;b.
  • Attributes supported: bold 1, dim 2, italic 3, underline 4, blink 5, reverse 7.
  • Each token resets with $begin:math:display$\\e[0m$end:math:display$ to avoid style bleed.

Date and time formatting

The custom date token supports a focused subset of \D{…} codes resolved at prompt time. Recognised codes include %F %Y %y %m %d %H %M %S %I %p %a %A %b %B.

Validation and bounds

Validation rules enforced by the generator
Field Type Min Max Step/Pattern Error Text Placeholder
Foreground colourstringn/an/a#RRGGBBInvalid foreground colour, expect #RRGGBB.
Background colourstringn/an/a#RRGGBBInvalid background colour, expect #RRGGBB.
Env variable namestring^[A-Za-z_][A-Za-z0-9_]*$Name is not valid.PATH
Custom date formatstringlen > 0non‑emptyCustom date format is empty.%F

I/O formats

Input and output summary
Input Accepted Families Output Encoding/Precision Rounding
Tokens, colours, attributes, delimiter, prefix, suffix Strings PS1 string UTF‑8 text with escaped control sequences Not applicable

Privacy & compliance

No data is transmitted or stored server‑side. Clipboard copy and file downloads run locally.

Assumptions & limitations

  • Heads‑up Terminal must support 24‑bit colour for exact RGB output.
  • Nonprinting wraps are added per token to keep cursor position stable.
  • Command substitutions rely on your shell configuration.
  • Git branch display requires the helper function below.
  • Overly long prompts may wrap on narrow windows.
  • Environment values are resolved by the shell at display time.
  • Imported strings with unusual escapes may need manual adjustment.
  • Colours are validated only for hex format, not contrast ratio.

Edge cases & error sources

  • Invalid hex colour values are rejected and flagged.
  • Empty custom date format yields a warning.
  • Environment names must start with a letter or underscore.
  • Unsupported terminals may ignore italic or blink attributes.
  • Clipboard access can be blocked by browser settings.
  • Very bright colours can reduce legibility on light themes.
  • Excessive nesting of literals complicates readability.
  • Long paths make prompts noisy without a basename token.
  • Jobs count may be zero while background tasks exist in other shells.
  • History and command numbers reset with fresh sessions.

Git helper snippet

parse_git_branch() { git branch --show-current 2>/dev/null | awk 'NF{print " (" $0 ")"}'; }

Step‑by‑Step Guide:

Shell prompts are composed from tokens and styles to produce a readable PS1 string.

  1. Add tokens in your preferred order.
  2. Pick colours and optional backgrounds for each token.
  3. Toggle attributes like bold or underline as needed.
  4. Set a delimiter, plus optional prefix and suffix.
  5. Preview the result and copy the generated PS1.

Example. Username at host, colon, working directory, space, and a dollar sign gives a compact everyday prompt.

  • Tip: keep delimiters short so the eye finds the tokens that matter.

FAQ:

Is my data stored?

No. Generation and copies occur locally and nothing is sent to a server.

Clipboard access may require permission.
Which date codes can I use?

The custom date token recognises %F %Y %y %m %d %H %M %S %I %p %a %A %b %B.

Codes are resolved at each prompt display.
How do I show the Git branch?

Add the Git Branch token and place the helper function in your shell startup file.

It prints the current branch wrapped in parentheses.
Why do colours look different?

Terminals vary in colour depth and themes. Test on light and dark backgrounds and avoid extreme values.

True colour support yields the best match.
Can I import my current PS1?

Yes. Paste it to parse common tokens, variables, and command substitutions, then refine any items.

Unusual escapes may require manual edits.
Does it work without network access?

Yes. Prompt generation runs locally and the preview uses sample values.

Drag and drop reordering gracefully falls back if unavailable.
What does a zero exit status mean?

It indicates the last command succeeded. Nonzero values suggest an error or partial failure.

Keep it visible when troubleshooting.

Advanced Tips:

Tip Use dim attribute for separators so content stands out.

Tip Keep path short by mixing basename with full path selectively.

Tip Add a newline token when commands produce long outputs.

Tip Reserve bright colours for status or errors only.

Tip Group identity tokens together and filesystem tokens together for quick scanning.

Tip Use the same delimiter everywhere to build muscle memory.

Glossary:

PS1
Primary prompt string evaluated before each command.
ANSI SGR
Terminal codes that control colour and text attributes.
Nonprinting wrap
Brackets that hide control codes from width counts.
Environment variable
Named value like PATH resolved by the shell.
Command substitution
Runs a command and inserts its output.
Delimiter
String placed between tokens in the prompt.