- Currently, your terminal looks something like this:
Perfectly functional, but not very easy on the eye. It quickly gets cluttered, and it's difficult to discern commands from output display. Luckily, there are ways to customize your terminals looks. To do this, you need to edit your .bash_profile file.
- From your home directory, type the following command in your terminal: (note that period '.' in the file name!)
A text editor window will open up in your terminal:
Copy and paste the following two lines:
export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@ \[\e[33m\]\w\[\e[0m\]\n\$ '
Now press Ctrl+x (Control key and x key pressed simultaneously) to close the editor. It prompts to save; press y, which puts you back on your command prompt.
alias ls='ls -GF'
- Now execute source .bash_profile for the change to take immediate effect (or you can log out and log back in). Your terminal now should look like:
What the first line in .bash_profile does is changing the commandline prompt to the current one: user name (green), current working directory (yellow), followed by a new line and the $ sign. The second line sets ls to be translated to ls -FG, which produces color-coded and detailed (e.g., "/" gets appended to directory names) listings.
- A word of caution: user definition files such as .bash_profile and .bashrc should be handled with care. When broken, they can leave you unable to operate in terminal environment. In such occasions, the file should be deleted by issuing this command: rm .bash_profile. This should be simple, in theory, but can be impossible if the file is mangled enough that you cannot even log into your terminal. And the problem is, the file is hidden within Mac Finder and therefore is not accessible this way! If this happens, try following the methods described here and here to first unhide the file, and then delete it from within Finder.
Defining your own command shortcuts in .bash_profile
Setting your locale
- Locale is a set of parameters that defines the user's language, character encoding, region and other special variant preferences. In your OS-X, the default locale is likely set to en_US.UTF-8, which roughly means "US English, UTF-8 (unicode) encoding". You can verify this by typing:
$ echo $LANG
- Yes, unicode is the present (almost) and future (most definitely) standard of character encoding, but it is not yet perfectly integrated into all aspects of computing. For the purpose of this class, in order for our various unix commands to work flawlessly, we will need to fall back to the more venerable encoding standard: ISO-8859-1.
- So how to set locale? You again edit the .bash_profile file in your home directory and place these lines (preferrably towards the beginning):
This sets your locale as en_US.ISO-8859-1: US English in ISO-8859-1 encoding.
Now either execute source .bash_profile or log out and log back in. Type echo $LC_ALL and echo $LANG to verify that your locale has been successfully changed. As always, if something goes wrong with the file and you find yourself unable to log in, you should remove .bash_profile and start over by following the directions above.