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

A shell prompt is the text you see before each command, and small mistakes in that line can have outsized consequences. The wrong host, the wrong directory, or an invisible non-zero exit status is often how a routine terminal session turns into cleanup work. This generator assembles a Bash-style PS1 string so that the prompt can carry that context in a form you can read quickly.

The tool lets you build the prompt from ordered elements such as user, host, working directory, time, shell details, exit status, history number, jobs, environment variables, plain text, and an optional Git branch helper. It then shows a styled sample preview and the literal string you would place in a shell startup file. That is much easier than shaping a prompt by hand out of escapes, color codes, and repeated trial-and-error edits.

That matters in ordinary work, not only in elaborate terminal themes. A short prompt can keep SSH sessions readable, a development prompt can keep branch and path visible, and a two-line prompt can separate status information from the next command line so errors stop blending into everything else.

The package also has clear boundaries. The preview uses sample values rather than your live shell state, the output is written for Bash-style PS1 syntax, and the import field is a convenience parser rather than a complete shell prompt decompiler. Those limits are useful to know before you trust the copied string.

Everyday Use & Decision Guide

The cleanest prompts usually start small. A baseline of user, host, directory, and prompt character is enough for many shells, and it keeps the first version readable while you decide which extra signals are actually worth the space.

Once that core works, add context only when you expect it to change what you do next. Exit status matters when you debug or automate. A branch marker matters when you spend most of your time inside repositories. Time markers matter when session timing or command history discipline actually affects the work.

  • Use Text elements for punctuation such as @, :, brackets, or separators instead of baking those characters into one large literal block.
  • Use an empty Delimiter when you want a tight user@host:path layout. Use a visible delimiter only when you want extra spacing between semantic units.
  • Take Warnings literally. In this package, they mean a malformed hex color, an invalid environment-variable name, or an empty custom date format.
  • Treat Import Existing PS1 as a starting point. It handles common Bash escapes and variables well, but arbitrary $(...) logic still needs manual review.
  • Do not trust the preview alone when branch output or command substitution is involved. The copied Generated PS1 string is the real artifact.

The page works best when you use it to shape the structure, then test that structure in a fresh Bash session where directory changes, branch changes, root prompts, and failing commands can all reveal whether the prompt is doing the job you intended.

Technical Details

PS1 is the Bash variable expanded before the shell reads the next command. This generator builds that string from prompt escapes, shell expansions, and literal text. Some elements map to native Bash prompt escapes, while others emit ordinary shell syntax that Bash resolves later when the prompt is drawn.

Representative PS1 element mappings
Element Emitted snippet Practical meaning
Username \u Shows the current user name
Hostname (short) \h Shows the host name up to the first dot
Working Dir \w Shows the current directory with home abbreviated
Dir (basename) \W Shows only the last path segment
Date (custom) \D{format} Uses a strftime-style format string at prompt time
History # \! Shows the history list entry number
Command # \# Shows the current-session command count
Prompt Char \$ Shows # for effective user ID 0 and $ otherwise
User ID $(id -u) Runs a command substitution that resolves to the numeric user ID
Git Branch $(parse_git_branch) Calls the helper function shown in the page so the current branch can appear when present

Two details from Bash matter more than they first appear. History # and Command # are not interchangeable, because Bash distinguishes the position of a command in the saved history list from the sequence number of commands executed in the current shell session. Likewise, custom dates in \D{...} are expanded by Bash itself using strftime-style formatting rules.

Element styling is applied one token at a time. When you choose a foreground color, background color, or text attribute, the tool emits ANSI styling around that token and then resets the style afterward. Those non-printing bytes are wrapped inside Bash prompt delimiters so cursor movement and line editing do not miscount invisible characters as visible width.

The preview and the copied string have different jobs. Live Preview substitutes sample values such as alice, zeus, main, and representative environment values so spacing and visual emphasis are easy to judge. Generated PS1 preserves the prompt escapes and shell expansions that Bash must interpret later, which is why the preview can look resolved while the copied string still contains prompt syntax.

The importer is intentionally partial. It recognizes common prompt escapes, environment variables, custom date blocks, newline markers, $(id -u), and generic command substitution shapes. Any generic $(...) block is rebuilt as the tool's Git-branch element, which makes import useful for rough reconstruction but unsuitable as proof that the original prompt has been recreated exactly.

The page also has a narrower date preview than Bash itself. The sample renderer covers common year, month, day, hour, minute, second, weekday, and month-name tokens, which is enough for most prompt mockups, but Bash can interpret a broader \D{format} pattern at runtime than the preview can fully demonstrate. This tool remains browser-only throughout, so prompt generation, validation, and export preparation all happen on the page.

Step-by-Step Guide

Build the structure first, then test the literal output in a real shell.

  1. Add a small base in Prompt Elements, such as Username, Hostname (short), Working Dir, and Prompt Char, so the list reflects the order you want before you worry about styling.
  2. Insert punctuation with Text elements and reorder items with the drag handle or the move buttons until the prompt reads naturally from left to right.
  3. Select each element and use Appearance to set foreground, optional background, and any text attributes. Keep an eye on Live Preview so low-contrast combinations are obvious early.
  4. Open Advanced and tune Prefix, Suffix, Delimiter, and Preview Background. If you want a multi-line layout, combine New Line with a suffix or prefix that matches the prompt style you prefer.
  5. If you are adapting an older prompt, paste it into Import Existing PS1, inspect the rebuilt element list, and fix any generic $(...) segments that were approximated as branch output.
  6. Copy Generated PS1, add the Git Helper Snippet if the branch element is present, then open a fresh Bash session and test in the contexts that matter to you.

A finished prompt should remain readable, keep cursor alignment intact while you edit commands, and still make sense when host, directory, branch, or exit status changes.

Interpreting Results

The page gives you three views of the same configuration. The preview is for layout, the table is for inspecting each emitted snippet, and the copied PS1 string is the actual shell artifact. If those three disagree in your head, trust the string that Bash will read rather than the mock preview.

  • If Warnings appears, treat the build as incomplete until the warning list is empty.
  • If Git Branch is present, the prompt still depends on the helper function shown in the page. Without that helper, the branch snippet will not resolve the way the preview suggests.
  • If you use Date (custom), the preview is only a sample renderer. The terminal result still depends on Bash interpreting the format string.
  • If you include both History # and Command #, expect them to diverge in real shells. That difference is normal, not a bug in the generator.

A prompt is successful when it stays readable in the terminal you actually use and exposes the context you rely on before you type the next command. That judgment belongs to the real shell, not just the preview box.

Worked Examples

Compact prompt for SSH sessions

A remote prompt often benefits from restraint. Use Username, a Text element containing @, Hostname (short), another punctuation element, Dir (basename), and Prompt Char, then leave the delimiter empty. The result keeps identity and location visible without wasting columns on a narrow terminal.

Status-aware development prompt

Suppose you want path and branch on one line and the next prompt on another. Add Exit Status, Working Dir, Git Branch, and New Line, then finish with Prompt Char. That layout separates the status signal from the command entry point so a failing command is harder to miss. It also makes the Git helper requirement obvious, because branch output only appears once the helper function is present in the shell startup file.

Imported legacy prompt with hidden shell logic

Paste a prompt that contains a generic command substitution such as $(date) and the importer can recognize the shape of the expression, but it does not rebuild a general command element. Instead, the package routes the segment into its branch-style placeholder, which is your cue to replace it manually with a built-in date element, a text block, or a different structure before you trust the output.

FAQ

Does this tool send my prompt to a server?

No. The preview, warning checks, table export data, JSON payload, and generated PS1 string are all assembled in the browser, and this slug does not ship a backend helper.

Will the generated string work for zsh or PowerShell?

The output is a Bash-style PS1 string. It uses Bash prompt escapes and Bash-style shell syntax, so it is not a PowerShell prompt function and it does not generate zsh theme syntax.

Why can the preview and my real shell look different?

The preview uses sample values and a limited date formatter so you can judge layout quickly. The shell still resolves variables, dates, command substitutions, root-versus-user prompt characters, and branch output at prompt time.

Why do History # and Command # not always match?

Bash treats them as different counters. One refers to the history list entry, while the other refers to the command sequence number within the current shell session.

What does the Git Helper Snippet do?

It defines the parse_git_branch function that the generated branch snippet calls. Without that helper in your shell startup file, the copied prompt string cannot show branch names the way the preview implies.

Glossary

PS1
The Bash variable expanded before the primary prompt is shown.
Prompt escape
A Bash backslash sequence such as \u or \w that expands into prompt content.
Command substitution
A shell expression such as $(id -u) that runs a command and inserts its output.
Non-printing sequence
Prompt bytes that affect styling or terminal control but should not count toward visible cursor width.
Delimiter
The string inserted between adjacent prompt elements.