Monday, December 5, 2011

How to make the Mac terminal less painful

So coming from the Linux world, I love my terminal/shell and find it so much easier and faster to do so many things. The problem is, the Mac OSX default settings are really quite painful if you are used to a GNOME or KDE terminal. Here is some pointers to help you out. In the Terminal -> Preferences you can change all of the color and window size settings. You can also specify which terminal theme is to be used by default. One setting that I high recommend you set is the "Use option as meta key" in the Keyboard sub-menu of the Preferences. This will make the Apple Option key work like you would expect.

Another thing I like to do is add/edit the ~/.bash_profile file. This is my .bashrc file from Linux that I have changed to work on OSX.


# ----------------------------------------
# Prompt
# ----------------------------------------
#     \[     Start a sequence of non-printing characters
#     \]     Ends the non-printing characters sequence
#     \e     An ASCII escape character, older systems use \033 (octal)
#     ]0;    xterm new icon name and title (icon name is for AfterStep 
#            Window Maker)
#     ]1;    xterm new icon name only
#     ]2;    xterm escape sequence for the title
#     \a     End xterm escape sequence

#     \h     Hostname
#     \w     Current directory
#     \u     Username

# Foreground Colors
#   Black = 30, Red = 31, Green = 32, Yellow\Orange = 33, Blue = 34
#   Magenta = 35, Cyan = 36, Light Gray\Black = 37, Default = 39
# Background Colors
#   Black = 40, Red = 41, Green = 42, Yellow\Orange = 43, Blue = 44
#   Magenta = 45, Cyan = 46, Light Gray\Black = 47, Default = 49

TIME_COLOR="\[\e[0;34m\]"
USERNAME_COLOR="$COLOR_DEFAULT"
COLOR_END="\[\e[m\]"


# ----------------------------------------
# Check to see if we are root.  If so
# change background color to red
# ----------------------------------------
if [ $UID == 0 ]; then
    USERNAME_COLOR="\[\e[0;37;41m\]"
fi

# ----------------------------------------
# Check to see if we have a fancy Xterm if
# not do not display title and window bar
# changes.
# ----------------------------------------
case "$TERM" in
xterm*)
    PS1="\[\e]2;\u@\h:\w\a\]\n[$TIME_COLOR\t$COLOR_END] \h\n[$USERNAME_COLORu$COLOR_END]:\w-> "
    ;;
dumb*)
    PS1='\h[\u]:\w-> '
    ;;
*)
    PS1="\n[$TIME_COLOR\t$COLOR_END] \h\n[$USERNAME_COLOR\u$COLOR_END]:\w-> "
    ;;
esac

export PS1


# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
alias ls='ls -G'
alias ll='ls -l -a'
#    export CLICOLOR=1
#    export LSCOLORS=ExFxCxDxBxegedabagacad
fi

export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH

No comments:

Post a Comment