Skip to content

Instantly share code, notes, and snippets.

@arthurprogramming
Last active August 29, 2015 14:11
Show Gist options
  • Save arthurprogramming/6b5d13532fe1ab78a9a2 to your computer and use it in GitHub Desktop.
Save arthurprogramming/6b5d13532fe1ab78a9a2 to your computer and use it in GitHub Desktop.
Indexing php projects for vim
#!/bin/bash
function doScan()
{
MAINFILE=$1
TYPE=$2
PARAM=""
BKP_FILE="cscope.files.bak"
if [[ $TYPE == "partial" ]] ; then
PARAM=" -mmin -3 "
elif [[ -e $MAINFILE ]] ; then
rm $MAINFILE
fi
LINESBEFORE=`cat $MAINFILE 2> /dev/null | wc -l`
find . $PARAM \( -path "./bob/data" -prune -o -iname "*.php" \
-o -iname "*.xml" \
-o -iname "*.ini" \
-o -iname "*.sql" \
-o -iname "*.html" \) \
>> $MAINFILE
LINESAFTER=`cat $MAINFILE | wc -l`
UPDATEDLINES=`expr $LINESAFTER - $LINESBEFORE`
echo "Files updated: $UPDATEDLINES" >> ../tagupdate_history
sort -u $MAINFILE > $BKP_FILE
mv $BKP_FILE $MAINFILE 2> /dev/null
}
function removeDeletedLines()
{
MAINFILE=$1
NEWFILE="cscope.files.new"
for line in `cat $MAINFILE`; do
if [[ ! -e $line ]] ; then
echo "$line deleted"
grep -v "^$line$" $MAINFILE > $NEWFILE
mv $NEWFILE $MAINFILE
fi
done
}
PROJECTPATH="/path/to/project/"
MAINFILE="cscope.files"
MAINFILEPATH=$PROJECTPATH$MAINFILE
cd $PROJECTPATH
TYPESCAN=$1
echo $TYPESCAN
echo "Starting script..." >> ../tagupdate_history
STARTTIME=$(date +%s)
date >> ../tagupdate_history
#if [[ -e $MAINFILEPATH ]]; then
# doScan $MAINFILEPATH partial
#else
doScan $MAINFILEPATH
#fi
if [[ -s $MAINFILEPATH ]]; then
if [[ -e ../runningcscope ]]; then
echo "Cscope is already running..." >> ../tagupdate_history
else
touch ../runningcscope
echo "Executing cscope" >> ../tagupdate_history
removeDeletedLines $MAINFILEPATH
/usr/local/bin/cscope -R -q -k -b 2>> ../tagupdate_history
echo "Done cscope" >> ../tagupdate_history
rm ../runningcscope
fi
fi
if [[ -e ../runningctags ]]; then
echo "Ctags is already running..." >> ../tagupdate_history
else
touch ../runningctags
echo "Executing ctags.." >> ../tagupdate_history
/usr/local/bin/ctags -R --fields=+aimS --languages=php
echo "Done ctags.." >> ../tagupdate_history
rm ../runningctags
fi
ENDTIME=$(date +%s)
echo "It took $(($ENDTIME - $STARTTIME)) second(s) to execute..." >> ../tagupdate_history
echo " " >> ../tagupdate_history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment