I use this little function (repo) 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 fzfor check another options fzf#installation.
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=""
root_dir=$USER_ROOT
if [ -n "$1" ]; then
filter_params="-q $1"
fi
find $root_dir -maxdepth 5 -name .git -type d -prune | sed 's/\/.git$//' | sort | fzf $filter_params --select-1 | read repo_path
if [ -n "$repo_path" ]; then
echo $repo_path
cd $repo_path
fi
}- You will need to replace the
$USER_ROOTbit on the$repo_pathline with the directory where you keep all of your code. As for me it's/drive/userfiles - You can open the dir via your faforite IDE. Change
cd $repo_pathtovim $repo_pathorcode $repo_path - To undo the action of the selected path press
[ESC]or[CTRL]+[D]or type:q
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 |
It is forked from https://gist.github.com/NileDaley/303090d4e8ee625807ee9f0ee1b8ef53