{{ summaryTitle }}
{{ summaryValue }}

{{ summaryLine }}

Source {{ sourceModeLabel }} Tokens {{ resultsReady ? computation.values.token_count : '—' }} Styled {{ resultsReady ? computation.values.styled_token_count : '—' }}

{{ promptExportStatus }}

Bash prompt composition controls
Builder preserves editable token styling. Import recognizes plain Bash prompt escapes and explicit environment, exit-status, user-ID, and Git-helper expansions.
The neutral default is #0f172a; only the preview canvas changes.
{{ computation.values.generated_ps1 }}
{{ promptExportStatus }}
{{ chartExportStatus }}

The chart renderer is unavailable. Category counts remain available in the token ledger.

TokenCategoryPS1 syntaxStyleCopy
{{ row.label }}{{ row.category_label }}{{ row.snippet }}{{ row.style_label }}
{{ ledgerExportStatus }}
{{ computation.values.setup_text }}
{{ setupExportStatus }}

A shell prompt is a small safety display placed immediately before every command. Showing the current user, host, directory, or last exit status can prevent a command meant for a local project from being run on the wrong machine or with the wrong privileges. Too much information has the opposite effect: the important clue disappears inside a long line that wraps on narrow terminals.

PS1 is Bash's primary interactive prompt variable. Bash expands prompt escapes such as \u for the user, \h for the short host name, and \w for the working directory each time it draws the prompt. Literal text stays fixed, while environment variables and approved command substitutions can change as the shell state changes.

Color introduces a second language inside the prompt. ANSI Select Graphic Rendition (SGR) sequences change foreground color, background color, or text attributes. Bash must be told that these bytes occupy no screen columns by enclosing them in \[ and \]. Missing those markers can make line editing, cursor movement, and command wrapping appear broken even when the colors look correct.

Prompt information and the decision it supports
Prompt clue Useful question Tradeoff
User and host Which account and machine will receive the command? Essential for remote work, but repetitive on a single local shell.
Working directory Which project or filesystem location is active? A full path gives context but can consume most of the line.
Exit status Did the previous command report success? The number needs a clear visual convention to avoid becoming noise.
Git branch Which branch will the next version-control command affect? Requires a helper command and adds work each time the prompt is drawn.

A preview can show spacing and approximate styling, but only Bash and the target terminal can prove that quoting, width, fonts, and escape support behave correctly. Test a temporary assignment first. Persist it in a startup file only after a fresh interactive shell opens cleanly.

How to Use This Tool:

Build from editable tokens when starting fresh, or import one plain Bash prompt when you need to inspect and revise an existing value.

  1. Choose Builder or Import PS1. Builder keeps token order and styling editable. Import accepts a raw value or one balanced single-quoted assignment, then parses only the supported prompt escapes and explicit expansions.
  2. Arrange the prompt tokens. Add identity, location, time, shell-state, status, version-control, or literal tokens in evaluation order. Use a Text token for individual separators, or Between tokens for one repeated separator.
  3. Apply styling sparingly. Set token colors or attributes where they communicate meaning. The preview background changes only the preview and never enters the generated prompt.
  4. Resolve validation messages. Remove unsupported imports, fix malformed environment names or date formats, and replace literal dollar signs, backticks, or line breaks with supported tokens.
  5. Test the generated assignment. Copy the Setup guide into a disposable interactive Bash session first. If a Git branch token is present, include the generated helper before the assignment. Add the result to ~/.bashrc only after the temporary test behaves correctly.

Interpreting Results:

Prompt code is the raw value Bash will expand. The preview uses representative values such as a sample user, host, path, and time; it does not execute Bash or reproduce every terminal's rendering. Check the final prompt string and then test it in the shell that will use it.

The Token ledger shows the emitted fragment for each token. Use it to find an unexpected escape, reset, or helper expansion. Styled counts tokens that emit at least one color or text-attribute code; it is not a readability score.

A successful import means the string fits the supported grammar, not that every embedded value is trustworthy. Review prompts copied from other people before running the generated setup text.

Technical Details:

Bash decodes prompt escapes after it reads PS1. Dynamic pieces therefore remain as escape or expansion syntax in the saved string; they are not replaced with the preview examples. Literal text is escaped for backslashes, and the complete value is placed in a shell-safe single-quoted assignment.

Transformation Core

  1. Validate the source mode, token count, literal text, environment names, date formats, and colors.
  2. Map each token to a Bash prompt escape, an approved expansion, or escaped literal text.
  3. Wrap styled token fragments in ANSI SGR start and reset sequences, with Bash nonprinting markers around both sequences.
  4. Join the fragments in order with the chosen delimiter, then add prefix and suffix text.
  5. Quote the completed value as a PS1='...' assignment and add the fixed Git helper only when required.
Supported Bash prompt token mapping
Purpose Supported syntax
Identity \u, $(id -u), \h, and \H
Location \w, \W, and \l
Date and time \d, \D{format}, \t, \A, \T, and \@
Shell state \s, \v, \V, \j, and ${NAME}
Status \!, \#, $?, and the root-aware \$
Version control The fixed $(parse_git_branch) expansion and its generated function.
Layout and literal content \n, \r, \a, \\, and validated literal text.

ANSI styling

A foreground color emits 38;2;r;g;b, and a background color emits 48;2;r;g;b. Bold, dim, italic, underline, blink, and reverse use SGR codes 1, 2, 3, 4, 5, and 7. A styled fragment has this shape:

\[\e[38;2;34;197;94;1m\]\u\[\e[0m\]

The opening and reset codes are both marked as nonprinting. Terminal support still varies, especially for italic, blink, reverse, and 24-bit color.

Import and validation rules

  • A prompt may contain at most 40 tokens. Builder settings and imported strings are each limited to 12,000 characters.
  • Environment names must begin with a letter or underscore and continue with letters, digits, or underscores, up to 64 characters.
  • Custom date formats are limited to 80 characters and cannot contain a closing brace or line break.
  • Literal text, prefix, suffix, and delimiters reject dollar signs, backticks, and line breaks. Prefix and suffix allow 120 characters each; the shared delimiter allows 20.
  • Import rejects existing ANSI wrappers and unsupported shell substitutions instead of preserving code it cannot model safely.

Safety and Compatibility Notes:

Prompt strings execute in an interactive shell environment. The builder limits literal expansion characters and the importer follows an allowlist, but the generated assignment still deserves review before it is placed in a startup file.

  • Use a temporary assignment before editing ~/.bashrc, and keep a second shell open while testing startup-file changes.
  • Run bash -n ~/.bashrc after editing. No output means Bash found no syntax error; it does not prove that every expansion is safe or fast.
  • This output targets Bash. Zsh, Fish, and other shells use different prompt systems.
  • The Git helper runs a command whenever the prompt is drawn, so very large or slow repositories can make the prompt less responsive.

Worked Examples:

Compact two-line prompt

Use short host, working directory, new line, and prompt-character tokens with a trailing space. With no styling or delimiter, the generated value is \h:\w\n\$ . Bash redraws the current host and path on the first line, then uses $ for an ordinary user or # for root on the second.

References: