Build your terminal prompt visually: drag usernames, paths, git branch, time, exit code and symbols into place, color each piece, and watch a live terminal preview. Copy the finished PS1 for bash or PROMPT for zsh straight into your shell config.
Last updated:
Elements drag into the prompt below, or click to add
Your prompt drag to reorder, click a piece to style it
Live preview
Add to ~/.bashrc
Advertisement
Advertisement
How to use the Bash Prompt Generator
Choose your shell: bash writes a PS1 variable, zsh writes PROMPT.
Load a preset or start empty, then drag elements such as Username, Full path or Git branch into the prompt bar. Clicking an element adds it too.
Click a piece to give it a text color, background or bold style, edit its text, or move and remove it.
Check the live preview in and out of a git repo, after a failed command and as root.
Copy the code to the end of ~/.bashrc or ~/.zshrc and run source ~/.bashrc (or open a new terminal).
Prompt escape codes in bash and zsh
Both shells replace special sequences in the prompt each time it is displayed. The generator writes the right code for each shell:
Shows
bash (PS1)
zsh (PROMPT)
Example
User name
\u
%n
alex
Host name (short / full)
\h / \H
%m / %M
laptop / laptop.home.lan
Working directory (full / last part)
\w / \W
%~ / %1~
~/projects/website / website
Time 24h with seconds
\t
%*
14:05:09
Time 24h HH:MM
\A
%T
14:05
Time 12h with AM/PM
\@
%@
02:05 PM
Date
\d
%D{%a %b %d}
Tue May 26
$ or # (root)
\$
%# (shows % or #)
$
Last exit code
$?
%?
1
Background jobs
\j
%j
0
New line
\n
a real line break
Color codes
bash uses ANSI escape sequences such as \[\e[1;32m\] (bold green) and \[\e[0m\] (reset). Foreground colors are 30-37 and bright 90-97; backgrounds are 40-47 and bright 100-107. zsh has readable shortcuts: %F{green}…%f for text color, %K{blue}…%k for background and %B…%b for bold. The exact shades depend on your terminal's color scheme, so the preview is an approximation.
Tips for a fast, readable prompt
Keep it short. Use the current folder instead of the full path, or a two-line prompt so long paths never squeeze your command.
Use color for meaning. A red exit code or a different color as root tells you something at a glance; too many colors just add noise.
Test in the current terminal first. Paste the code directly into the shell to try it; nothing is saved until you add it to your config file.
Avoid slow commands. Everything inside $( … ) runs before every prompt, so keep such functions light.
Frequently asked questions
What is PS1 in bash?
PS1 is the shell variable that defines the primary prompt bash shows before each command. It can contain plain text, backslash escapes such as \u (user), \h (host) and \w (working directory), color codes, and command substitutions that run every time the prompt is drawn.
How do I make my custom prompt permanent?
Add the generated code to the end of ~/.bashrc for bash or ~/.zshrc for zsh, then run source ~/.bashrc (or source ~/.zshrc) or open a new terminal. On macOS, Terminal opens login shells, so bash users may need to source ~/.bashrc from ~/.bash_profile.
Why do colors need \[ and \] in bash?
Color codes are invisible but bash counts every character to know where the cursor is. Wrapping escape sequences in \[ and \] tells bash they take no space. Without them, long commands wrap onto the same line and editing with the arrow keys becomes garbled.
How does the git branch part work?
The generated function asks git for the current branch name with git symbolic-ref, falls back to the short commit hash when HEAD is detached, and prints nothing outside a repository. The prompt calls it each time it is drawn, so the branch updates as soon as you switch.
How do I reset my prompt to the default?
Remove or comment out the prompt lines in ~/.bashrc or ~/.zshrc and open a new terminal. To undo it only in the current session, run exec bash (or exec zsh), which starts a fresh shell that reads your config files again.
Does it work with zsh and Oh My Zsh?
Yes. Switch to zsh to get a PROMPT using %n, %m, %~ and %F{color} codes, with PROMPT_SUBST enabled for the git branch. If you use Oh My Zsh or another framework, set ZSH_THEME="" or place the code after the framework loads so the theme does not overwrite it.
Why do some symbols show as boxes?
Characters like ❯, ➜ and λ need a font that contains them. Most modern terminal fonts do; if yours does not, use plain characters such as $, > or : instead.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.