fast alternative to find for finding git directories
Hey,
I have a small script to switch between projects. All my projects are in a deeply nested directory that is equal to their upstream source (eg. ~/projects/github.com/junegunn/fzf/).
It works by using find to enumerate all directories under ~/projects/ that contain a .git/ directory and passes that to fzf. Unfortunately this is pretty slow somehow because findtakes a long time. When using fzf directly it's super fast, but I can't restrict the selection to only include git root directories.
Is there a better way of getting a similar result? All I want is to have a fast way of switching between projects
dev () {
project="$(find $HOME/projects -type d -name .git -prune -exec sh -c 'dirname $(realpath --relative-to $HOME/projects {})' \; 2>/dev/null | fzf -1)"
if [[ $? -ne 0 ]]
then
return $?
fi
projectDir="$HOME/projects/$project"
pushd $projectDir
}