Added cache for gclone
This commit is contained in:
parent
06016d1ef6
commit
d6ef67f6c5
|
@ -25,11 +25,24 @@ if [ -d "$GCLONE_PATH" ]; then
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
# Final path to the repo
|
# Final path to the repo
|
||||||
repo_path=$GCLONE_PATH/$server/$user/
|
repo_path=$GCLONE_PATH/$server/$user
|
||||||
mkdir -p $repo_path
|
mkdir -p $repo_path
|
||||||
|
|
||||||
mv $tempdir/$repo $repo_path
|
mv $tempdir/$repo $repo_path
|
||||||
|
|
||||||
|
if [ ! -f $GCLONE_PATH/.cdgcache ]; then
|
||||||
|
# If there is no cache, generate the cache manually
|
||||||
|
_cdg_refresh_cache
|
||||||
|
else
|
||||||
|
# If there is a cache, just append the current dir at the end
|
||||||
|
# and sort it back
|
||||||
|
echo $repo_path
|
||||||
|
echo $repo_path >> $GCLONE_PATH/.cdgcache
|
||||||
|
echo $repo_path/$repo >> $GCLONE_PATH/.cdgcache
|
||||||
|
cat $GCLONE_PATH/.cdgcache | sort | uniq > $GCLONE_PATH/.cdgcache.tmp
|
||||||
|
mv $GCLONE_PATH/.cdgcache.tmp $GCLONE_PATH/.cdgcache
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove the temp dir
|
# Remove the temp dir
|
||||||
|
@ -41,7 +54,8 @@ if [ -d "$GCLONE_PATH" ]; then
|
||||||
echo "This function expects a single parameter"
|
echo "This function expects a single parameter"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
found_dirs=`find $GCLONE_PATH -maxdepth 3 -name $1 | sort`
|
|
||||||
|
found_dirs=`_cdg_existing_dirs | grep /$1$`
|
||||||
total=`echo $found_dirs | wc -l`
|
total=`echo $found_dirs | wc -l`
|
||||||
|
|
||||||
if [[ "" == "$found_dirs" ]]; then
|
if [[ "" == "$found_dirs" ]]; then
|
||||||
|
@ -65,16 +79,33 @@ if [ -d "$GCLONE_PATH" ]; then
|
||||||
fi
|
fi
|
||||||
return 3
|
return 3
|
||||||
else
|
else
|
||||||
cd $found_dirs
|
cd $found_dirs > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "cd didn't work, refreshing cache..."
|
||||||
|
_cdg_refresh_cache
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_cdg() {
|
_cdg() {
|
||||||
_arguments "1: :($(find $GCLONE_PATH -maxdepth 3 -exec basename {} \;))"
|
_arguments "1: :($(_cdg_existing_dirs | rev | cut -d '/' -f 1 | rev))"
|
||||||
}
|
}
|
||||||
|
|
||||||
compdef _cdg cdg
|
compdef _cdg cdg
|
||||||
|
|
||||||
|
_cdg_refresh_cache() {
|
||||||
|
find $GCLONE_PATH -maxdepth 3 \
|
||||||
|
-not -name ".cdgcache" \
|
||||||
|
-not -name "git" | sort > $GCLONE_PATH/.cdgcache
|
||||||
|
}
|
||||||
|
|
||||||
|
_cdg_existing_dirs() {
|
||||||
|
if [ ! -f $GCLONE_PATH/.cdgcache ]; then
|
||||||
|
_cdg_refresh_cache
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat $GCLONE_PATH/.cdgcache
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue