Tuesday, January 19, 2010

Making cygwin work

You usually try to recreate the environment that you are most comforatable with. So when I got my work laptop, one of the first things I did was to install cygwin. Now cygwin works pretty well for the most part, however its a disaster when converting between windows style and unix style of file paths. Then of course you discover cygpath command which does exactly that.

Classpath for JAVA:

However this does not fix you java classpath issues. I struggled with this for a long time till I found this: just make sure that the path separator is ";" and put a double quote around the classpath :

cygwin > java -cp ".;./classpathdir/;dir" Test

Using Console for cygwin

If you have cygwin on the windows cmd console, then its time to switch to console (Yes its console, though I wish they could have dreamt up a better term just to avoid any confusion.) Its available at http://sourceforge.net/projects/console/. It's pretty lets you do multiple tabs , unlimited resizing etc. Best of all you can set cygwin bash as your default shell !!




Use SSH instead of Putty

If you have made is so far, why not open ssh instead of putty. Don't get me wrong. I love putty myself, however it doesn't have tabs (well it does but you have to download putty manager for that). You get the advantage of multiple tabs, plus you can script your access now. (Note: cygwin will not download openssh by default, you need to download it). If you use password less access to your servers, you can use ssh-agent to cache your keys in memory. I have a function in my .bashrc that I just run to cache the keys:


alias keyon='ssh-add /cygdrive/c/Documents\ and\ Settings/user/My\ Documents/PrivateKeys/id_rsa'
alias keyoff='ssh-add -D'
alias keylist='ssh-add -l'

function ssh_agent_start
{
SSHAGENT=/bin/ssh-agent
if [[ ! -a $SSHAGENT ]]; then
echo "SSHAGENT not found $SSHAGENT"
return
fi
echo Starting SSH-agent
SSHAGENTARGS="-s"
if [ -n "$SSH_AUTH_SOCK" ]; then
echo "Killing existing agent"
eval `$SSHAGENT -k`
fi
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
keyon
}

Now you can easliy login to your favourite server without password:
> ssh_agent_start
> ssh user@myserver