e-cd: Fast Directory Changer

Karel Kubat, e-tunity

2000 ff.

Table of Contents

1: Introduction

2: Installation

3: Shell configuration



1: Introduction

e-cd is one of those tiny tools to make a developer's life easier (and maybe even bearable). The idea behind e-cd is that changing directories should be easier: say xd ulac instead of cd /usr/local/apache/conf.

e-cd is a small C program that takes its argument and tries to resolve it letter by letter into a directory. When that succeeds, a cd command is sent to the output. The shell should then pick up the output and change-dir there.

2: Installation

The installation of e-cd is very easy: the archive e-cd.tar.gz is unpacked, and a make install is done in the source directory e-cd/, which is created in the unpacking.

A successful installation will put the binary e-cd in the directory pointed to by the environment variable $EBINDIR. The e-tunity utility library e-lib is necessary during compilation.

3: Shell configuration

Following the installation, commands such as cd `e-cd ulac` can be executed. But that's not yet quite what we want. To enable a transparent usage of e-cd in a shell, the following function can be used:

xd () { 
    if [ -z "$1" ]; then
        popd >/dev/null;
    else
        if [ -z "$2" ]; then
            newdir=`/e-cd $@`;
            test "$newdir" != "." && pushd "$newdir" >/dev/null;
        else
            echo 'xd - fast directory changer' 1>&2;
            echo 'Usage: xd ulb - takes you to say /usr/local/bin' 1>&2;
            echo '   or: xd     - takes you to previous directory' 1>&2;
            return 1;
        fi;
    fi
}

This is an example of a Bash function, that can be placed in a user profile ~/.profile, or in a system-wide profile /etc/profile. Functions for other shells (csh, tcsh) are not further shown here.