Some OS X X11 Tips

November 5, 2007 – 5:32 pm

I have been setting up this new iMac for the past week or so, trying to get all the little things squared away just the way I like them. It’s taken a bit of effort given that I am moving from a Linux system (Fedora Core 4) to OS X, and I’m trying to get Apple’s X11 installation to do the kinds of things I’m used to in Linux. So far, so good.

I installed MacPorts immediately after installing X11 from Apple. MacPorts lets me install a whole slew of things, the most important of which is my window manager of choice, IceWM. A quick sudo port install icewm gets me up and running on that front. One of the little things I like about IceWM is that it allows me to tile my xterm windows as they open. They don’t sit on top of each other, and they don’t open up at random positions on the screen. They open in an orderly fashion, one next to the other, and then below each other. A quick edit of my ~/.icewm/keys file allows me to open new terminals with the click of two buttons, Cmd T:

key "Meta+t"                    xterm -ls -geometry 120x30

Great. Now, I want to change both the prompt and the title of these xterm windows. Ideally, I would like the title of the xterm windows to change dynamically. I was fortunate to stumble across this bit of code on the web, which I placed in my ~/.bashrc file:

term_directory_update ()
{
    if [[ ! "$OLDPWD" = "$PWD" ]]; then
        echo -en  "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007";
    fi
}

if [[ $TERM = 'xterm' || $TERM = 'xterm-color' || $TERM = 'linux' ]]; then
#   export PS1="\[\e[33;1m\][\[\e[31;1m\]\h:\W\[\e[33;1m\]]>\[\e[0m\] "
   export PS1="[\u \W]\$ "
fi
if [[ $TERM = 'xterm' || $TERM = 'xterm-color' ]]; then
   export PROMPT_COMMAND=term_directory_update
fi
#
if [ $TERM = 'dumb' ]; then
  export PS1="dumb:"
  return 0
fi

Another thing I did to allow myself to SSH to our computational cluster without a password is install SSHLogin for OS X. It appears as though the easiest way to find it is to search Google for sshlogin os x. When I initially log in to OS X, I am prompted for the passphrase for my private SSH key. After I enter it this one time, every xterm I open recognizes it, and I get the same behavior I would get from ssh-add in Linux. As best as I could tell, there was not a straight forward way to make all xterm windows in Apple’s version of X11 recognize ssh-add the way it is recognized in Linux. But SSHLogin fixed that for me very easily.

Post a Comment