My latest bash toy: a “cd” replacement

I just made this little cd function that is a drop-in replacement for the builtin bash cd command. The idea was to make it really easy and productive to navigate around to commonly used directories in bash without forcing someone to learn new habits like in the case of pushd, popd, and a bunch of other stuff like cdargs and gotodir.

cd ()
{
    if [ "$*" = "" -o "$*" = "-" ]; then
        builtin cd $*;
        return;
    fi;
    realpath=$(realpath $*);
    if [ -z "$realpath" -o ! -d "$realpath" ]; then
        realpath=$(realpath ~/recent_dirs/$* 2> /dev/null);
    fi;
    if builtin cd $realpath; then
        if [ "$*" = "" -o "$*" = "-" ]; then
            return;
        fi;
        ln -s $realpath ~/recent_dirs 2>/dev/null;
    else
        :;
    fi
}

Restarting fetchmail automatically

I use fetchmail (in daemon mode) to pull down mail from a POP server to my local box, where I then serve it up with the Courier IMAP server. Problem I had was when my box rebooted, fetchmail could not automatically restart because it needs a password to proceed (I don’t want to store the password in my .fetchmailrc). My solution was to add the following to my .bashrc:

if [ -x "/usr/local/bin/fetchmail" ]; then
  if ! killall -0 fetchmail 2> /dev/null; then
     echo "killall -0 fetchmail failed - starting fetchmail..."
     fetchmail
  fi
fi