Skip to content
gohacks.dev
Tooling

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

ada@web-1:~/code/app (main) $ git status

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.

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.

Share

Frequently asked questions

Where do I put the PS1 line?
In ~/.bashrc for bash or ~/.zshrc for zsh, then open a new terminal or source the file.
Why does my coloured bash prompt break line wrapping?
The colour codes are not wrapped in the non-printing markers, so bash counts them as visible characters. The generated PS1 wraps every code.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools