From 1c300d3a76a786a83e8a70b7a399db94c8bcf5b7 Mon Sep 17 00:00:00 2001 From: Evan Chiu Date: Sun, 10 Apr 2016 17:32:37 -0700 Subject: [PATCH] lib: add git function to determine repository name (#4989) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4989 Co-authored-by: Marc Cornellà --- lib/git.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index 2054fe272..00cb00b19 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -199,3 +199,12 @@ function git_current_user_name() { function git_current_user_email() { command git config user.email 2>/dev/null } + +# Output the name of the root directory of the git repository +# Usage example: $(git_repo_name) +function git_repo_name() { + local repo_path + if repo_path="$(git rev-parse --show-toplevel 2>/dev/null)" && [[ -n "$repo_path" ]]; then + echo ${repo_path:t} + fi +}