Monday, January 7, 2008

Make Leopard's Terminal show the ENTIRE path.

There are quite a bit of changes to Leopard's Terminal, one of which, I am not too keen on. In Tiger, when you were using the Terminal, navigating deep into folders and directories you could easily check the latest prompt to see where exactly you currently were. However soon after messing with Leopard's Terminal, I was saddened to see that it no longer did this, but instead only displays the current name of the directory that you are in.

At first, this didn't bug me to much, however it gets really annoying typing in pwd every-other time just to make sure you are in the right directory

"...am I in /usr/bin/ or am I in /usr/local/bin/... am I in /Library/, or /System/Library/, or am I in ~/Library/?!"

This got old quickly so I decided to ask my Linux mentor, who also happens to be my boss, if he had a solution. He did a little research, we found a solution, and I was so happy to have figured this out I thought I'd post a blog in hopes that I can help other people out who are also bothered by this.

First things first: You'll need to know what "~" means. ~ refers to your "Home" folder. You're Home folder is located in the /Users/ folder in Leopard. A lot of times this is your full name. In my case, my Home Directory is jonathansmith68. The tilde comes handy when you want to cd to your Home Directory quickly.

-Simply enter the following command into Terminal at any time in order to cd (or changedirectory) into your Home Folder.

cd ~


Also note that anytime you open Terminal, by default, it places you in your Home Directory.

Now that we've discussed what the Home Directory is, explaining how to add this functionality will be much easier.

First you'll have to create a file named ".bash_profile" inside your Home Directory. It is under my impression that most, if not all Linux distros already have this file, but it appears that Leopard does not, so you'll have to make it yourself.

Note: Files and Folders that begin with "." are hidden in Leopard. In terminal in order to see these hidden files and folders you must enter the "ls" (list) command along with the "-a" (all) option. This will show all the files and folders located in your current directory.

You can create the ".bash_profile" file in any kind of text editor, whether it be Vi Editor, TextEdit, or TextMate. I'm lazy and didn't want to learn Vi so I decided to just create the file in TextEdit.

1.) Open TextEdit and Enter the following String of text:

export PS1="[\u@\h \w]\\$

2.) Go to File --> Save As...

3.) Uncheck the Box that says "If no extension is provided, use ".txt"."

4.) Name the file ".bash_profile"

5.) Make sure to save this to your Home Directory, this can be found in the sidebar and/or the drop down box and is represented by a small Home Icon.

6.) A Dialog box will pop up telling you that filenames that being with a "." are reserved for the system (hidden files) and asks if you are sure that you want to use the "." in the beginning. Simply click "Use ".""

Once the file has been saved into your Home Directory, all you need to do is quit out of Terminal, and reopen it.

You should now be able to see the full Directory Path at all times!




Before (only shows the current directory, not entire path)


After (shows the entire path of the current directory)


I'd like to give credit to this website for most of the information. Thanks to Mac OS X's Unix roots, it was possible to adapt this to Leopard.

5 comments:

Dale said...

vim for life!

Dale said...

cd

by itself does the same thing as

cd ~

...if only Dorothy would've known about the cd command...

xhili said...

Watch out!

you're missing a "

you have it as

export PS1="[\u@\h \w]\\$

but it should be export PS1="[\u@\h \w]\\$"

I use pico to edit text files within Terminal

kujjhotika said...

Thank you very much!!! It was really helpful!

Tom K. said...

The pwd command is also useful.