Sunday, June 10, 2007

Mac for scientific computation: Part1




Last semester I got a sexy white Macbook with my adviser's money. I got it mainly because it looked cool. I knew very little about the OS other than its an unix variant. Over the period I configured, tweaked it, installed some software and it became a very productive tool for me. In this and next few blogs I will explain how I configured my Mac to suit my needs. Remember my needs are 1) programming, scientific computation and related stuff 2) presentations and document creation 3) fun stuff (movies, songs... etc.) 4) and all other.
  • Quicksilver
The first thing that comes to my mind w.r.t productivity is Quicksilver. Its a free tool and allows you type one or two letters and get the application you want. Its use is similar to Alt+F2 on KDE or gnome. Sure you can get all the important apps on Dock or look in Applications folder, but the programming guys know the importance of keyboard shortcuts. Some might say use Spotlight, but its slow for me.
  • Terminal
Terminal is important for all programmers using nix'es. Mac offers an application called Terminal.app and I found its better than other terminals like xterm because it has nice anti-aliased fonts. For anti-alias fonts explore window settings. But its text is monochrome. In linux, you find terminals displaying folders, files, executables, symbolic links in different colors. It helps in finding things quickly. To get colors for terminal you have to tweak it. After extensive googling, I was able to manage this. I am presenting all the info needed here. For getting colors, a variable called LSCOLORS has to defined. My .bash_profile file contains these lines
export CLICOLOR=1
#export LSCOLORS=ExFxCxDxBxegedabagacad
export LSCOLORS=gxexcxdxbxegedabagdcdx
Let me explain what the string means. The capital letters in the string display things in bold and small letters correspond to normal display. Each pair of characters corresponds to a file attribute. The first char corresponds to foreground and the second char of the pair corresponds to background. Here are the attributes in the order.

Directory
Symlink
Socket
Pipe
Executable
Block
Character
Exec. w/ SUID
Exec. w/ SGID
Dir, o+w, sticky
Dir, o+w, unsticky

As you see, there are too many attributes and if you specify different color for each attribute, you will get lost. I don't care if the executable has suid/sgid bits set or not (if you are a sysadmin in a big company, you may care). So I give identical colors to all executables and similarly for directories. Also you hardly encounter things like pipes and sockets in work folders. So don't worry about them. So the things we have to look at are 1st, 2nd, 5th and last two pair of chars. So in the string gxexcxdxbxegedabagdcdx I care only about things highlighted with color. Now how do we set the colors. Just look at the table below
a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

Now you should be able to see colors in the terminal. Look at the picture to see how terminal displays files on my mac. But if you ssh to a linux machine, terminal again displays files in monochrome. To get colors when using ssh you have to do couple of extra things. If you open terminal preferences you will see an option saying how to define $TERM. This is the variable passed to the remote machine telling which (kind of) terminal you are using. For my machine, I defined it as xterm-color. In the linux machine, create a .dir_colors file in your home directory. Just copy /etc/DIR_COLORS and rename it. Go through that file and configure how colors should be displayed on the linux machine terminals. If you look into that file you will find lot of lines starting with TERM. There should be a line which corresponds to $TERM defined on your mac. I added the line
TERM xterm-color
Then add the following lines in .bashrc file on the linux machine.
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b ~/.dir_colors`"
alias ls='ls --color=auto'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
fi

This should help you to get colors with ssh also. Look at the picture to see how colors appear after sshing to a linux machine.

No comments: