diff options
author | Evan Chiu <evan@evanchiu.com> | 2016-04-10 17:32:37 -0700 |
---|---|---|
committer | Marc Cornellà <marc.cornella@live.com> | 2020-02-10 21:11:31 +0100 |
commit | 1c300d3a76a786a83e8a70b7a399db94c8bcf5b7 (patch) | |
tree | ba95b9f96ae540d87bc6d6b2b7a1645f405e0cf0 /lib/git.zsh | |
parent | 22cf7159ec09722421ffe355e852410823d7f49d (diff) | |
download | zsh-1c300d3a76a786a83e8a70b7a399db94c8bcf5b7.tar.gz zsh-1c300d3a76a786a83e8a70b7a399db94c8bcf5b7.tar.bz2 zsh-1c300d3a76a786a83e8a70b7a399db94c8bcf5b7.zip |
lib: add git function to determine repository name (#4989)
Closes #4989
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
Diffstat (limited to 'lib/git.zsh')
-rw-r--r-- | lib/git.zsh | 9 |
1 files changed, 9 insertions, 0 deletions
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 +} |