Bash and zsh Prompt Generator
Build a bash PS1 or zsh PROMPT with user, host, directory, time, Git branch and exit status, each in a colour of your choice, with a live preview.
Free · No sign-up · Your inputs stay in your browser
Input
Build a bash or zsh prompt (PS1)
Output
Prompt
bash (~/.bashrc)
PS1='\[\e[31m\]$(s=$?; [ $s -ne 0 ] && echo "[$s] ")\[\e[0m\]\[\e[32m\]\u\[\e[0m\]@\[\e[32m\]\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\[\e[33m\]$(__git_ps1 ' (%s)')\[\e[0m\] $ '
zsh (~/.zshrc)
PROMPT='%F{red}%(?..[%?] )%f%F{green}%n%f@%F{green}%m%f:%F{blue}%~%f%F{yellow}${vcs_info_msg_0_}%f %# '
In bash every colour code is wrapped in \[ \], which tells readline the characters take no space; without them, long commands wrap onto the same line and history editing goes wrong. __git_ps1 comes with Git's git-prompt.sh; in zsh, enable vcs_info in ~/.zshrc with autoload -Uz vcs_info and precmd() { vcs_info }, plus setopt prompt_subst.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
The square brackets in bash
Bash needs every colour escape wrapped in escaped square brackets, which tell readline the characters take no space on screen. Without them, readline miscounts the prompt's width, long commands wrap onto the same line and editing history garbles the line. The bash prompt documentation lists the escapes such as user and working directory.
Git branch in the prompt
For bash, __git_ps1 comes with Git's contrib git-prompt.sh, which many distributions install. zsh has vcs_info built in: load it in ~/.zshrc, call it from precmd and enable prompt_subst. Both read the repository on every prompt, so they add a few milliseconds in very large repositories.