Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active October 9, 2015 11:43
Show Gist options
  • Save raghubetina/7c584eb605f41769ab15 to your computer and use it in GitHub Desktop.
Save raghubetina/7c584eb605f41769ab15 to your computer and use it in GitHub Desktop.
Customizing Your Terminal Prompt

Customizing Your Terminal Prompt

tl;dr

Run the following command from anywhere in Terminal:

echo PS1=\"\\w $ \" >> ~/.bash_profile

That's it! Now restart Terminal; your prompt should look like mine. For example,

~/code/homework $ _

The Long Version

On Mac OS X, it is possible to customize your Terminal sessions in many ways.

The first and most common thing you probably want to do is change how your Command Prompt looks. By default, it will look something like this:

Your-Macs-Name:homework your-username$ _

To make it easier to know exactly where I am at all times, I prefer that the Command Prompt include the full path to my current directory. I also don't like the $ symbol very much. So I prefer something like this:

~/code/homework $ _

In order to change how your prompt looks, you need to customize your Bash Profile. You can do this by editing a file located at ~/.bash_profile.

The dot in front of the filename indicates that it is a hidden file, which means it won't show up if you look at your home folder in Finder. You won't even see it if you do ls in Terminal. You have to do

ls -a

if you want see all of the hidden files and folders along with the regular ones.

Initially, you may not even have a .bash_profile file in your home folder. In that case, you'll have to create one. Either way, you can open or create the file with the command

subl ~/.bash_profile

assuming you already completed the Sublime Setup guide (otherwise you won't have the subl command available to you).

If subl doesn't work, you can use nano ~/.bash_profile to open the file. Nano is another plain text editor that OS X comes with -- but it is purely text-based application. You can type in to it, but the mouse won't work, etc. After you are done editing, CTRL-X to exit, and save changes.

You should see a file in Sublime. It might already have some stuff in it, which is fine. Add the following line to customize your Command Prompt:

export PS1="\w $ "

Technically, what we are doing here is setting an environment variable, PS1, which tells Terminal how we want the prompt to look. The \w is shorthand for "my current working directory", and then we are telling it to draw a space, a dollar sign, and then another space, before the cursor. You can re-arrange it however you like.

Anyway, now save, exit, and restart Terminal. Your prompt should now look different. Congrats!

(Later on, you will see how environment variables are also used to store secret info, like your email passwords or API access tokens, securely -- what you don't want to do is put them right in to your code, because then if you push to a public repo on GitHub by accident, nefarious people can and will steal your secrets!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment