September 19, 2006
Mac OSX Terminal – For Switchers
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.
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.
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.
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.
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"’
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.