#!/bin/sh

updatedb_program=/usr/local/bin/updatedb
db_name=PATH
config_name=.updatedbrc

argv=""
global=0
for arg in $@; do
    if [ $arg = "-g" ]; then
        global=1
    else
        argv+=" $arg"
    fi
done

if [ $global = 0 ]; then
    db="`pwd`/$db_name"
fi

if [ -n "$db" ]; then
    localpath=`pwd`
    config="$HOME/$config_name"
    if [ -f $config ]; then
        findoptions=`grep $db -A 1 $config | tail -n 1`
        findoptions=${findoptions//-path .\//-path $localpath/}
    fi
    argv="--localpaths=$localpath --output=$db $argv"
fi

if [ -n "$findoptions" ]; then
    exec $updatedb_program "--findoptions=$findoptions" $argv
else
    exec $updatedb_program $argv
fi

