Changing your ZSH Prompt in 60 Seconds

Posted on 10 July 2024

If you're using a newish version of Mac, or Kali Linux then chances are your terminal uses zsh shell by default. But most of this article applies for users of bash shells too.

You might have noticed that the default prompt in these terminals looks something like this:

yourname@yourcomputer currentdirectory %
Terminal prompt with a long name

There are good reasons why that's the default - since it changes if you ssh into another machine, it's each to see at a glance which user and machine you're logged in to.

And that default is fine if you're got a short name and a short computer name, but not so great if you're got a long name or made the mistake of naming your computer in a creative way.

But there's no need to stay with the default prompt; it's super easy to change it to pretty much anything you want.

The left prompt is defined in a variable called PROMPT (or PS1), and the right prompt is defined in a variable called RPROMPT

So all you have to do is export PROMPT or RPROMPT with a new string, and if you want to permanently use that as your new default then you should also add it to your .zshrc file.

Here's a video showing how quick it is to change your prompt. Scroll down for the commands you can copy into your terminal.

Default prompt:

export PROMPT="%n@%m %1~ %# "

Replacing username and server:

export PROMPT="working@Home %1~ %# "

Adding some colour:

export PROMPT="%F{red}working%f@Home %1~ %# "

Adding more colour:

export PROMPT="%F{red}working%f@%F{green}Home%f:) %1~ %# "

Adding a smily:

export PROMPT="%F{red}working%f@%F{green}Home%f😊 %1~ %# "

Showing only 1 level of your current path:

export PROMPT="%1~ 😊 "

Showing 2 levels of your current path:

export PROMPT="%2~ 😊 "

Showing 3 levels of your current path:

export PROMPT="%3~ 😊 "

Adding the current time into the right of the terminal:

export RPROMPT="%T" 

Adding some emphasis and changing the colour:

export RPROMPT="%S%F{250}%T%f%s"
Terminal with custom prompt

The colour numbering convention is a bit weird. Here are the basic colours and greyscale colours. If you want a full list then just search for xterm color schemes

000
#000000
001
#800000
002
#008000
003
#808000
004
#000080
005
#800080
006
#008080
007
#c0c0c0
008
#808080
009
#ff0000
010
#00ff00
011
#ffff00
012
#0000ff
013
#ff00ff
014
#00ffff
015
#ffffff
232
#080808
233
#121212
234
#1c1c1c
235
#262626
236
#303030
237
#3a3a3a
238
#444444
239
#4e4e4e
240
#585858
241
#626262
242
#6c6c6c
243
#767676
255
#eeeeee
254
#e4e4e4
253
#dadada
252
#d0d0d0
251
#c6c6c6
250
#bcbcbc
249
#b2b2b2
248
#a8a8a8
247
#9e9e9e
246
#949494
245
#8a8a8a
244
#808080