zsh plugin to change directory to git repository root directory
Inspired by id:hitode909 blog post.
Put cd-gitroot and _cd-gitroot files somewhere in your $fpath and add the following line to your .zshrc:
autoload -Uz cd-gitroot
# download all files
% cd /path/to/dir
% git clone https://github.com/mollifier/cd-gitroot.git
And add the following lines to your .zshrc:
fpath=(/path/to/dir/cd-gitroot(N-/) $fpath)
autoload -Uz cd-gitroot
If you use Antigen, add the following line to your .zshrc:
antigen bundle mollifier/cd-gitroot
If you use Oh-my-zsh:
-
Clone this repository in oh-my-zsh's plugins directory:
git clone https://github.com/mollifier/cd-gitroot.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/cd-gitroot
you
2. Activate the plugin in ~/.zshrc
:
plugins=( [plugins...] cd-gitroot)
-
Source
~/.zshrc
to take changes into account:source ~/.zshrc
If you use zgen, add the following to your .zshrc
zgen load mollifier/cd-gitroot
to your .zshrc
with your other zgen load
commands.
You can set alias to this function. e.g.
alias cdu='cd-gitroot'
cd-gitroot [PATH]
If PATH isn't specified, change directory to current git repository root directory. else change directory to PATH instead of it. PATH is treated relative path in git root directory.
-h display help and exit