Tuesday, April 8, 2008

Linux Live Search...

So... The other day I decided to set up 'locate' to find files in my home network shares, /home/ghostis and /sandbox/ghostis. To do so, I did the following:


% mkdir /home/ghostis/Documents/locate

Added the an updatedb job to my crontab on my laptop:

15,30 * * * * updatedb --netpaths='/home/ghostis /sandbox/ghostis' --output=/home/ghostis/Documents/locate/locatedb --localpaths=' '

Now I can do faster searches of filenames via:

locate -d ~/Documents/locate/locatedb sometextinfilename


But, then I thought, "What's the absurd extreme?"
Linux Live Search!
So I baked a quick bash script:

% cat linux_live_search.sh


#!/bin/bash
clear
echo "Please type something. (Escape spaces. Ctrl-C to quit)"
echo "------------------------------------------"
echo "Query: $WORD"
echo "------------------------------------------"
while read -s -n1 KEY
do
clear
if [ "$KEY" = "" ]
then
WORD=`echo "$WORD"| sed -e 's/.$//'`
else
WORD="`echo "$WORD"`$KEY"
fi
if [ "$KEY" = "" ]
then
unset WORD
fi
if [ -z "$WORD" ]
then
echo "Please type something. (Escape spaces. Ctrl-C to quit)"
else
killall locate > /dev/null 2>&1
locate --all -d ~/Documents/locate/locatedb "$WORD" | head -30
fi
echo ""
echo "------------------------------------------"
echo "Query: " "$WORD"
echo "------------------------------------------"
done




Try not to choke on your coffee...

Cheers,

-Adam