Wednesday, August 28, 2013

Getting the prompt to look right in MacOS X

New Macbook Air. Yessir! The Lenovo went back, and instead came along a Macbook Air, core i7, with 4GB of RAM and 512GB SSD sweetness. The battery life is amazing. Other things still need to be worked out, like you know, the immediate lack of Excel (and other Office products). Numbers is able to open and work with some basic Excel workbooks, but none of the shortcuts are around (obviously). And Pages is no Word (ya think?).

Also, one of the first things I did was get iTerm2 on there. I prefer it to the native Terminal application. E.g. it allows you to draw a window border so that you can see where overlapping terminals are. Plus I like the fact that I don't have to futz with the background (it comes with a dark background and white text by default).

And since I got terminal going, I need to colorize the bash prompt (naturally!). Here's a useful bash snippet.


cat ~/.bash_profile
PS1='\e[1;32m\u\e[m@\e[0;31m\h\e[m:\e[2;33m\w\e[m # \n\$ '
# PS1='\u@\h:\w # \n\$ '
alias ls='ls -G'
alias dir='ls'
alias grep='grep --color'
alias rebash='source ~/.bash_profile'

resultant output looks like below:

user@machine:/your/path #
$


The prompt colorization is in the first line of the script that describes the shell variable PS1. Colors are specified as \e[x;ym stuff you want to colorize \e[m
The \e[m are shell escape markers. Think of them as "quotes" for the shell.

More references here:
http://en.wikipedia.org/wiki/ANSI_escape_code
http://en.wikipedia.org/wiki/Control_character
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html


No comments: