Frequently Asked Question
What is PS1, and how do I customise my prompt?
PS1 is the shell variable that holds the primary prompt string, the text bash
prints before each command. A typical default is \u@\h:\w\$, which expands to
chris@laptop:~/projects$. Bash recognises a list of backslash escapes inside PS1:
\u is the username, \h the short hostname, \w the current directory, \t
the time, \$` a `#` for root and `$ for everyone else, \n a newline, and
\[...\] brackets non-printing sequences (for colour) so bash can measure the
visible width correctly.
A common minimalist prompt is export PS1='\u@\h:\w\$ '. Many developers add
git-branch information by sourcing the git-prompt.sh script that ships with git
and embedding $(__git_ps1) in PS1. For something faster, more cross-shell, and
configured by a file rather than a string, install Starship or Powerlevel10k. There
are also PS2 (the continuation prompt, default > ), PS3 (the select
prompt), and PS4 (the set -x debug prefix).