Friday, February 06, 2009

Speeding up Cygwin login

On Windows I use Cygwin extensively. So I open a lot of login shells. However these shells are sometimes slow to load, especially when my host is busy with other jobs.

While editing my ~/.bash_profile I noticed code like this:

if [ -d "some path element" ]; then
    PATH="some path element:$PATH"
fi

This is a common idiom. However, it is making a separate fork to /bin/test every time.

A simple improvement:

if [[ -d "some path element" ]]; then
    PATH="some path element:$PATH"
fi

A little trying it out and the verdict: Wow, big improvement.

2 comments:

Anonymous said...

Recent versions of bash have test, [ and [[ implemented as built-ins. This has been true for a while. Are you not using bash?

Signed,

A fellow cygwin jpmorganite

P.S. We find the biggest issues are populating /etc/passwd and /etc/group and dealing with PATH entries on network drives for which the cost of a forked test is completely immaterial.

Brian Oxley said...

It it isn't the fork, I'm unsure why this is. I found this result empirically.