From 11fda8a2350df5c4d7425bcae38f40b1a6488d8e Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 21 Jun 2023 15:15:58 +0200 Subject: [PATCH] zsh/git: add alias to go back to root dir --- .gitconfig | 1 + .zsh/30_alias.zsh | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.gitconfig b/.gitconfig index c4f38c9..07dcd52 100644 --- a/.gitconfig +++ b/.gitconfig @@ -70,6 +70,7 @@ up = pull --rebase --autostash rebaseour = "rebase -Xours" rank = "shortlog -s -n --no-merges" + root = rev-parse --show-toplevel [rebase] # when rebasing, update the other common branch too. # See https://andrewlock.net/working-with-stacked-branches-in-git-is-easier-with-update-refs/ diff --git a/.zsh/30_alias.zsh b/.zsh/30_alias.zsh index a1c0dbf..e3de0cc 100644 --- a/.zsh/30_alias.zsh +++ b/.zsh/30_alias.zsh @@ -65,3 +65,9 @@ alias -g S='&> /dev/null &' alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' alias senv='source ~/venv/bin/activate' +alias r='if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) != 'true' ]]; then + >&2 echo "Not a git repository" + return 1 +else + cd $(git root) +fi'