From e1ec501c552712d21174661946f4470a19f1d387 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 14 Jan 2025 06:57:40 +0200 Subject: [PATCH] chore(config): add local version of git-root cmd --- config/alias | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/alias b/config/alias index c76dc52..7b6ec32 100755 --- a/config/alias +++ b/config/alias @@ -12,8 +12,19 @@ alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." +# Get git repository root path +get_git_root() +{ + # check that we are in a git repository + if git rev-parse --is-inside-work-tree &> /dev/null; then + git rev-parse --show-toplevel + else + >&2 msgr err "Not in a git repository" + fi +} + # cd to git root directory -alias cdgr='cd "$(git root)"' +alias cdgr='cd "$(get_git_root)"' # interesting folders, and shortcuts alias .='cd $HOME'