Categories
Unix

How to change your command line prompt

Your command line welcomes you with a prompt.

Default OSX terminal may look like this.

PS1 is the variable used by your shell to determine your command line prompt

RPS1 determines your right hand prompt.

Note, you can always `echo` this variable to see what these are currently set to.

By default, mine is set to %n@%m %1~ %#

These % (percent) symbol combinations are prompt expansions (docs)

  • %n– is the special variable $USERNAME (echo this to check)
  • @ – literally the “@“ sign,
  • %m – hostname up to the first “.”
  • %1~ – current working directory for “1” ancestor
  • Additionally you may like..
  • %~ – current working directory with home aliased to “~”
  • %D – date in yy-mm-dd (International) format
  • %W – date in mm-dd-yy (US) format
  • %t – time in am/pm format
  • %* – time in 24 hour format

Note, your prompt can even accept emoji’s 🚀

command+control+space brings up the emoji keyboard on Macs

How to apply this to every new terminal window

If you are using bash, add your PS1=... command to your ~/.bash_profile file.

If you are using zsh, add your PS1=... command to your ~/.zshrc file

* emoji’s are not available on all machines, but great on those are.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s