Prompt String 1 (PS1) Generator
Build online Bash PS1 prompts from ordered shell tokens, colors, import parsing, setup notes, and exports for readable terminal and SSH workflows.Generated Bash PS1
| Element | PS1 snippet | Copy |
|---|---|---|
| {{ row.label }} | {{ row.snippet }} | |
| No elements. | ||
| Item | Value | Copy |
|---|---|---|
| {{ row.label }} | {{ row.value }} |
A Bash primary prompt is the short piece of text Bash expands before it waits for the next command. A useful prompt keeps the session grounded: user, host, directory, command state, and the final prompt character can all reduce wrong-terminal mistakes when the shell moves between local work, SSH sessions, containers, and admin accounts.
The prompt is small, but it sits at a busy decision point. A developer may need the current directory and branch before running a migration. A system administrator may need the host name and prompt character before changing service state. Someone debugging a failed command may want the last exit code visible before typing the next command. The best prompt is not the longest one; it is the one that surfaces the state you check repeatedly without crowding the input line.
PS1 is the Bash variable that controls that primary prompt. It can contain plain punctuation, Bash prompt escapes, shell parameter expansion, command substitution, date formatting, newlines, and non-printing terminal control sequences. That mix is useful because a prompt can be both readable text and live shell state.
A prompt should still be treated as a reminder, not proof. A branch name does not show whether a repository is clean. A host name does not replace checking where a destructive command will run. A root-style prompt character warns that the effective user is elevated, but it cannot tell whether the next command is safe.
Technical Details:
Bash expands the primary prompt in a specific order. Prompt escapes such as \u, \h, and \w are decoded first. After that decoded string is ready, Bash may perform shell expansions such as $VAR, $?, and $(command). That is why two prompt fragments can look similar in a preview but behave differently at runtime.
Visible characters and non-printing bytes also need different treatment. ANSI style sequences change colour or text attributes, but they do not occupy terminal columns. Bash uses \[ and \] to mark those bytes so command-line editing can keep cursor position, wrapping, and backspacing aligned.
- Join prefix, ordered prompt elements, delimiter text, and suffix into one
PS1string. - Wrap any foreground colour, background colour, or text attribute with non-printing prompt markers.
- Leave live shell expressions intact so Bash resolves user, host, directory, date, status, and command output later.
- Reset styling after each styled element so one coloured segment does not leak into the rest of the prompt.
| Prompt element | Generated snippet | Runtime meaning |
|---|---|---|
| Username | \u |
Current user name. |
| Hostname (short) / Hostname (full) | \h / \H |
Host name before the first dot, or the full host name. |
| Working Dir / Dir (basename) | \w / \W |
Current directory path, or only the final path segment. |
| Date and time | \d, \D{format}, \t, \A, \T, \@ |
Built-in date or time forms, including custom strftime patterns for \D{format}. |
| History # / Command # / Jobs | \! / \# / \j |
History position, current-session command count, or active job count. |
| Exit Status | $? |
Exit code from the previous command after Bash performs shell expansion. |
| Environment variable | $NAME |
Value of a valid shell variable name at prompt time. |
| User ID / Git Branch | $(id -u) / $(parse_git_branch) |
Command substitution, including a branch helper function when that helper exists in the shell. |
| Prompt Char / New Line / Text | \$, \n, literal text |
Root-aware prompt character, line break, or escaped punctuation and labels. |
Custom date prompts rely on the C library strftime format vocabulary. Common patterns include %F for an ISO-style date, %H:%M for 24-hour time, and %a for the abbreviated weekday name. Locale and time zone can change the final text, so a date preview is a guide rather than a guarantee for every Bash environment.
| Field or feature | Accepted form | Warning or limit to check |
|---|---|---|
| Foreground and background colours | #RRGGBB hex colour values. |
Invalid hex values are listed in Warnings and should be fixed before copying. |
| Environment variable name | Starts with a letter or underscore, then letters, numbers, or underscores. | Names such as 9PATH are not valid shell variable names. |
| Custom date format | Non-empty strftime pattern inside \D{...}. |
An empty date format is reported as a warning. |
| Imported prompt text | Common Bash prompt escapes, variables, date formats, newlines, prompt character, and command substitutions. | Generic $(...) expressions are not a full decompile of arbitrary shell logic and need review. |
Two Bash counters are easy to mix up. \! is the history number of the command, while \# is the command number in the current shell session. They often differ because the history list can include commands restored from earlier sessions.
Everyday Use & Decision Guide:
Start with a short identity-and-location prompt before adding status details. A good first build is Username, a Text token containing @, Hostname (short), a punctuation token such as :, Working Dir or Dir (basename), and Prompt Char. Keep Delimiter empty for a tight user@host:path$ style, or use a single space when each segment needs more room.
Add signals only when they change what you do next. Exit Status is useful when failed commands need to stay visible. Git Branch helps in repository-heavy work, but it needs the helper shown in Setup Notes. New Line works well when the first line should carry context and the second line should stay clean for input.
- Use separate Text tokens for punctuation. Moving or recolouring
@,:, brackets, or spaces is easier when they are not buried inside one long text value. - Check Sample terminal preview for spacing and contrast, then check Generated PS1 for the string Bash will evaluate.
- Open Element Breakdown when a token looks wrong. It shows each element and the snippet emitted for that element.
- Use Setup Notes when the prompt includes the Git branch helper or when you want a copyable assignment form.
- Clear Warnings before trusting the result. In this generator, warnings point to invalid colour values, invalid environment-variable names, or an empty custom date format.
Importing an older prompt is a head start, not a promise that every shell trick will be rebuilt exactly. Common Bash escapes and simple variables are recognized. A prompt that hides a large command substitution or custom function should be reviewed in Element Breakdown before the new string replaces your current setup.
After copying the result, test it in a fresh Bash session with the same kind of work you normally do: inside and outside a Git repository, after a failing command, in a long path, and on any remote host where the prompt will be used.
Step-by-Step Guide:
Build the prompt in small pieces, then verify the copied string in Bash.
- Add the first few rows in Prompt elements. A compact base such as Username, Hostname (short), Working Dir, and Prompt Char should make the summary badge show the expected token count.
- Add Text elements for separators such as
@,:, brackets, or spaces. Use the drag handle or arrow buttons until Sample terminal preview reads in the order you expect. - Open each element row and set Foreground color, optional Background color, and any attributes such as Bold, Dim, Underline, Blink, or Reverse. If Warnings appears after a colour edit, replace the value with a valid
#RRGGBBcolour. - Use Advanced for Prefix, Suffix, Delimiter, Import existing PS1, and Preview background. A delimiter changes spacing between all neighbouring elements, while text tokens give you finer control over punctuation.
- If you import an existing string, inspect the rebuilt rows. Fix any generic command substitution, invalid variable name, or empty custom date before copying Generated PS1.
- Open Setup Notes before installing the prompt. Copy the assignment form, and copy the Git helper snippet when Git Branch is part of the element list.
- Copy Generated PS1, paste it into the right Bash startup file or a temporary test shell, and confirm cursor wrapping, colours, exit status, branch output, and prompt character behavior.
A finished prompt should be short enough to type after, clear enough to prevent wrong-context commands, and stable enough that command-line editing does not drift when the line wraps.
Interpreting Results:
Trust the copied Generated PS1 string more than the preview. The preview is a visual sample with placeholder values such as a sample user, host, path, branch, and exit code. Bash still resolves live variables, dates, command substitutions, history counters, and the root-aware prompt character when the prompt is displayed.
| Result surface | Use it for | Do not overread |
|---|---|---|
| Generated PS1 | The prompt string Bash should evaluate. | It still depends on your Bash version, startup file, helper functions, terminal, and current shell state. |
| Sample terminal preview | Checking rough layout, colours, spacing, and line breaks. | It is not a live transcript from your shell. |
| Element Breakdown | Auditing each token's emitted snippet. | It does not prove that a helper function exists in the installed shell. |
| Setup Notes | Copying the assignment form and any Git helper note. | It cannot choose the correct startup file for every operating system and shell setup. |
| JSON | Saving the current inputs, derived prompt, table rows, and warnings. | It stores the configuration, not the runtime result from Bash. |
Stop and fix the build if Warnings is visible. A warning means at least one field can produce an invalid or misleading prompt segment, even if the sample preview still appears usable.
Worked Examples:
Compact SSH prompt
For a narrow SSH window, use Username, a Text token set to @, Hostname (short), another Text token set to :, Dir (basename), and Prompt Char. Leave Delimiter blank. Generated PS1 should contain the important runtime snippets \u, \h, \W, and \$, with colour markers added only around styled elements.
Development prompt with failure state
A repository prompt can start with Exit Status, Working Dir, Git Branch, New Line, and Prompt Char. Generated PS1 should include $? for the last exit code and $(parse_git_branch) for branch output. Setup Notes should also show the helper function, because the branch segment depends on that function being present in the shell.
Imported prompt with a bad variable name
An imported prompt such as \u@\h:\w \D{%F} \$ should rebuild into user, host, path, date, and prompt-character rows. If you then add an environment variable named 9PATH, Warnings should report the invalid name because Bash variable names cannot begin with a digit. Rename it to PATH before copying Generated PS1.
FAQ:
Does this generate prompts for zsh or PowerShell?
No. The generated value is a Bash PS1 string with Bash prompt escapes and Bash shell expansion syntax.
Why are colour codes wrapped in special markers?
Colour and attribute bytes do not print visible characters. Wrapping them with \[ and \] helps Bash keep cursor movement and line wrapping aligned.
Why does the preview differ from my real terminal?
The preview uses sample values and a limited date formatter. Your real shell resolves user, host, path, exit code, date, variables, and command substitutions at prompt time.
What happens if I use the Git Branch element without the helper?
Generated PS1 calls $(parse_git_branch). If that function is not defined in your Bash startup file, the branch segment will not behave like the preview.
Can the importer understand every existing prompt?
No. It recognizes common prompt escapes, variables, dates, newlines, prompt characters, and command substitutions, but arbitrary shell logic still needs manual review in Element Breakdown.
Does my prompt text need a server-side helper?
No server-side helper is used for the prompt content. Building, previewing, warnings, and export preparation run in the browser after the page assets have loaded.
Glossary:
- PS1
- The Bash variable expanded before the primary prompt is displayed.
- Prompt escape
- A backslash sequence such as
\uor\wthat Bash replaces with live prompt content. - Shell expansion
- The Bash step that resolves variables, command substitutions, arithmetic expansion, and quote removal after prompt escapes are decoded.
- Command substitution
- A shell expression such as
$(id -u)that runs a command and inserts its output. - Non-printing sequence
- Terminal control bytes that change style or behavior without adding visible columns to the prompt.
- Delimiter
- Text inserted between neighbouring prompt elements.
- strftime
- The date-formatting vocabulary used by Bash for
\D{format}prompt escapes.
References:
- Bash Reference Manual: Bourne Shell Variables, GNU Project.
- Bash Reference Manual: Controlling the Prompt, GNU Project.
- The GNU C Library Manual: Formatting Calendar Time, GNU Project.