diff --git a/zsh/functions/cd_git_root.zsh b/zsh/functions/cd_git_root.zsh new file mode 100644 index 0000000..8f82c27 --- /dev/null +++ b/zsh/functions/cd_git_root.zsh @@ -0,0 +1,10 @@ +function gr() { + local git_root + git_root=$(git rev-parse --show-toplevel 2>/dev/null) + if [[ $? -eq 0 && -d $git_root ]]; then + cd "$git_root" + else + echo "Not in a git repository or could not find the git root." + fi +} + diff --git a/zsh/zshrc b/zsh/zshrc index 7e96646..6bf9d75 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -13,3 +13,5 @@ autopair-init source ~/.zim/modules/fzf-tab/fzf-tab.plugin.zsh source ~/.config/zsh/prompt.zsh + +source ~/.config/zsh/functions/cd_git_root.zsh