1c300d3a76a786a83e8a70b7a399db94c8bcf5b7

Author
Evan Chiu <evan@evanchiu.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

lib: add git function to determine repository name (#4989)

Closes #4989

Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/lib/git.zsh b/lib/git.zsh
 2index 2054fe272843f6516e6a1641ca9bbad32dc7ac37..00cb00b19e81de958c54d6a548be146ac9a7563a 100644
 3--- a/lib/git.zsh
 4+++ b/lib/git.zsh
 5@@ -199,3 +199,12 @@ function git_current_user_name() {
 6 function git_current_user_email() {
 7   command git config user.email 2>/dev/null
 8 }
 9+
10+# Output the name of the root directory of the git repository
11+# Usage example: $(git_repo_name)
12+function git_repo_name() {
13+  local repo_path
14+  if repo_path="$(git rev-parse --show-toplevel 2>/dev/null)" && [[ -n "$repo_path" ]]; then
15+    echo ${repo_path:t}
16+  fi
17+}