I use this little function on the command line to allow me to switch between different repositories easily using fzf
- fzf
- zsh or bash
If you don't already have fzf installed you can install it via Homebrew:
brew install fzf
Depending on if you're using bash or zsh as your shell, you can add the following code to ~/.bashrc
or ~/.zshrc
function repo {
filter_params=""
if [ -n "$1" ]; then
filter_params="-q $1"
fi
repo_path=$(find ~/code -name .git -type d -prune -maxdepth 5 | sed 's/\/.git$//' | sort | fzf $filter_params --select-1)
cd $repo_path
}
You will need to replace the ~/code
bit on the $repo_path
line with the directory where you keep all of your code.
Save the file, then reload your shell using either bash
or zsh
.
Command | Example | Description |
---|---|---|
repo | Display all git repositories | |
repo {query} | repo kiosk | Display all git repositories matching query. If only 1 result matches query, it'll select that result automatically |
The next line fixes that
https://gist.github.com/contributorpw/af7bf73df217bfa41a43a14977f75c49