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 ")"}'; }
| Element | PS1 Snippet | Copy |
|---|---|---|
| {{ r.label }} | {{ r.snippet }} | |
| No elements. | ||
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.
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.
| Symbol | Meaning | Unit/Datatype | Source |
|---|---|---|---|
| \u | Username | string | Derived at prompt time |
| $(id -u) | User ID | number → string | Derived at prompt time |
| \h | Hostname short | string | Derived at prompt time |
| \H | Hostname full | string | Derived at prompt time |
| \w | Working directory | path | Derived at prompt time |
| \W | Directory basename | path | Derived at prompt time |
| $(parse_git_branch) | Git branch via helper | string | Derived at prompt time |
| \v | Bash version | string | Derived at prompt time |
| \V | Shell release | string | Derived at prompt time |
| \s | Shell name | string | Derived at prompt time |
| \d | Date short | string | Derived at prompt time |
| \D{fmt} | Date custom format | string | Derived at prompt time |
| \t, \A, \T, \@ | Times 24 h and 12 h | string | Derived at prompt time |
| $VAR | Environment variable | string | Derived at prompt time |
| \! | History number | number → string | Derived at prompt time |
| \# | Command number | number → string | Derived at prompt time |
| \j | Jobs | number → string | Derived at prompt time |
| $? | Exit status | number → string | Derived at prompt time |
| \$ | Prompt character | string | Derived at prompt time |
| \n | New line | control | Literal |
| text | Literal characters | string | Literal |
$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$ $
| Parameter | Meaning | Datatype | Typical Range | Notes |
|---|---|---|---|---|
| prefix | Text placed before the prompt | string | Often empty or newline | Escaped safely |
| delimiter | String between tokens | string | Space by default | Preserves spacing |
| suffix | Text after the last token | string | $ by default | Escaped safely |
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.
| Field | Type | Min | Max | Step/Pattern | Error Text | Placeholder |
|---|---|---|---|---|---|---|
| Foreground colour | string | n/a | n/a | #RRGGBB | Invalid foreground colour, expect #RRGGBB. | — |
| Background colour | string | n/a | n/a | #RRGGBB | Invalid background colour, expect #RRGGBB. | — |
| Env variable name | string | — | — | ^[A-Za-z_][A-Za-z0-9_]*$ | Name is not valid. | PATH |
| Custom date format | string | len > 0 | — | non‑empty | Custom date format is empty. | %F |
| 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 |
No data is transmitted or stored server‑side. Clipboard copy and file downloads run locally.
parse_git_branch() { git branch --show-current 2>/dev/null | awk 'NF{print " (" $0 ")"}'; }
Shell prompts are composed from tokens and styles to produce a readable PS1 string.
Example. Username at host, colon, working directory, space, and a dollar sign gives a compact everyday prompt.
No. Generation and copies occur locally and nothing is sent to a server.
Clipboard access may require permission.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.Add the Git Branch token and place the helper function in your shell startup file.
It prints the current branch wrapped in parentheses.Terminals vary in colour depth and themes. Test on light and dark backgrounds and avoid extreme values.
True colour support yields the best match.Yes. Paste it to parse common tokens, variables, and command substitutions, then refine any items.
Unusual escapes may require manual edits.Yes. Prompt generation runs locally and the preview uses sample values.
Drag and drop reordering gracefully falls back if unavailable.It indicates the last command succeeded. Nonzero values suggest an error or partial failure.
Keep it visible when troubleshooting.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.