September 19, 2006

Mac OSX Terminal – For Switchers

I’m a switcher who move dot the Macintosh in February of 2006.  I moved because I figured at the very least I would have a slick all in one unit that would eventually be able to run windows and run quieter than the AMD system I was replacing.  I have even gone so far as to move the wife over and I have my macbook as well.  The machines all are great performers, when they are running(the macbook suffered from RSD and has yet to earn my trust back).

There has only been one nagging issue, Terminal.app.  It has been a real pain in the rear when everytime I hit the home or end keys I get the top of the terminal window or the bottom of it.  In most terminal apps it takes you to the begining of the line or the end of the line.  I also have not taken the time to fix the colors.  So tonight I decided to figure all of this stuff out I came up with much more than i set out to do proving how truely powerful the Terminal.app is so I decided to write something up just in case I forgot it later on down the line.

Looking through the menus I was very surprised at the amount of options available they are almost daunting.  I quickly settled on the command + I(hrm Get Info from the finder window)  I managed to get all my color and font settings in here just the way I wanted them and I was very pleased with this.  I then saw the options for Window and Keyboard.  These are what I now want to document.

picture 4.png

First with Keyboard I was always annoyed that hitting end or home took you to the begining or end of the Terminal.app window instead of the current line you were on in the window.  This is easily fixed by finding end under the Key Column and clicking delete, do the same for home.  Next find the shift end select it click edit set the modifier to none and click ok.  Do the same with the shift home key.  Now you have both the home and end keys working like they do in most other terminal applications.

picture 1.pngpicture 2.png

Another thing I always liked for my terminal sessions and the windows command shell is a way to identify which machine I’m on in that window.  Apple does a fine job of this but I have my own style I’ve gotten used to seeing that includes ansi colors and the time.  So I setout to figure out how to impliment this in the Mac OSX terminal.  It just so happens mac os uses the bash shell, good for me because that is what I spent hours creating my prompt for.

I edited the /etc/profile and added the following line

export PS1="\033[34;47;1m[\033[31;1m\u\033[34;1m@\033[35;1m\H\033[34;1m:\033[33;1m\w\033[34;1m] [\033[30;1m\t\033[34;1m]\033[0m\n#"

it was important to put it here so it isn’t over written by the bashrc file.

picture 3.png

Yea I now have my pretty shell.  Thats when I noticed the window looked all messed up and said I was connected to a linux box on my network I had disconnected from a while back.  I checked under the Window option and I noticed a lot of settings there I unchecked everything but the command key because that seemed useful being able to see what button to press to bring that window to the front.

picture 5-1.png

Next I had to figure out what was setting the window title.  It wasn’t long before I found the env var PROMPT_COMMAND.   The window title get set to whatever that variable is set to.  So I quickly made a little propt to let me know what user machine and dir I’m in for the window title.  Now as I mouse over the minimized windows I can see this information pop up above the window.

The mac didn’t include this info so I had to set it manually in the /etc/bashrc I added the following lines

USER="`id -un`"
HOSTNAME=`/bin/hostname -s`
PROMPT_COMMAND=’echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"’

picture 7.png

Now that makes for a more Mac like terminal experience.  There was more because my hacked tivo wasn’t plaing right I was able to use the following in the /.profile to get the same effect on that machine.

USER="root"
HOSTNAME="TiVo"
HOME="/var/hacks"
export PROMPT_COMMAND=’echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"’

That along with the bash PS1 and all my machines are consistent and working on the network now feels more like home, on the mac.

Leave a comment

You must be logged in to post a comment.