From 5d12ddb93e95b05eb0c53373d47b1407072e8d5b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 13:53:29 +0200 Subject: fixed git aliases needing functions --- config/essentials/zsh/functions.zsh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'config/essentials/zsh/functions.zsh') diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 9d16c0d..189dd22 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -94,4 +94,38 @@ sgd () { test "$(parse_git_remote)" && echo "$PWD \e[0;32m*push/pull\e[0m" done - } +} + +# Git functions +# Returns current branch +function git_current_branch() +{ + command git rev-parse --git-dir &>/dev/null || return + git branch --show-current +} + +# Check if main exists and use instead of master +function git_main_branch() { + command git rev-parse --git-dir &>/dev/null || return + local ref + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do + if command git show-ref -q --verify $ref; then + echo ${ref:t} + return + fi + done + echo master +} + +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return + fi + done + echo develop +} -- cgit v1.2.3